Home > Blockchain >  Laravel 9 - Error Class BooksSeeder does not exist
Laravel 9 - Error Class BooksSeeder does not exist

Time:05-30

When i run php artisan make:seeder --class=BooksSeeder I am getting the following error:

The "--class" option does not exist.

Can anyone help me out? I'm still new to Laravel

My DatabaseSeeder Class:

<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // \App\Models\User::factory(10)->create();
    }
}

My BooksSeeder Class:

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Books;


class BooksSeeder extends Seeder
{
    public function run()
    {
        $faker = \Faker\Factory::create();
        for ($i = 0; $i < 50; $i  ) {
            Books::create([
                'name' => $faker->sentence,
                'author' => $faker->name,
                'publish_date' => $faker->date,
            ]);
        }
    }
}

CodePudding user response:

You are using wrong syntax.

To create seeder, use:

php artisan make:seeder BooksSeeder

To run seeder, use:

php artisan db:seed --class=BooksSeeder
  • Related