Database seeder error Laravel: Target class [DatabaseSeeder] does not exist

49 Views Asked by At

I've tried to run php artisan db:seed but encounter an error:

INFO  Seeding database.

   */
    public function run(): void
    {

        \App\Models\User::factory(10)->create();
        \App\Models\User::factory(2)->unverified()->create();
        \App\Models\Task::factory(20)->create();

        // \App\Models\User::factory()->create([
        //     'name' => 'Test User',
        //     'email' => '[email protected]',
        // ]);
    }

}

   Illuminate\Contracts\Container\BindingResolutionException

  Target class [DatabaseSeeder] does not exist.

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:914
    910▕
    911▕         try {
    912▕             $reflector = new ReflectionClass($concrete);
    913▕         } catch (ReflectionException $e) {
  ➜ 914▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    915▕         }
    916▕
    917▕         // If the type is not instantiable, the developer is attempting to resolve
    918▕         // an abstract type such as an Interface or Abstract Class and there is

      +22 vendor frames

  23  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

I've tried to follow serveral thread:

  1. Checked the file location and make sure there's no typo. file located in database/seeders/DatabaseSeeder.php
  2. I also tried to dump auto loader by running composer dump-autoload

But the issue still presist. Is there any other way to fix this? Thank you.

1

There are 1 best solutions below

2
Sambhav On

Can you check the namespace of DatabaseSeeder.php file. Make sure it's correct. By default it's Database\Seeders