in laravel 8 with seeding , i has this issue Target class [TableSeeder] does not exist

Solution 1:

From laravel 8 Seeders and factories are now namespaced


To accommodate for these changes, add Database\Seeders namespace to your seeder classes.

namespace Database\Seeders;

In addition, move all seeder files from previous database/seeds directory to database/seeders folder.


In your case remove all lines started with use Database\Seeders\...
from DatabaseSeeder.php file

It should solve the issue,

You can also run dump-autoload & fresh migration with seed,

composer dump-autoload

php artisan migrate:fresh --seed

Solution 2:

For Laravel 8 you need to make the below changes to an existing project for seeding to work:

  1. Add the Database\Seeders namespace to your DatabaseSeeder.php and other seeder files :
<?php

namespace Database\Seeders;
  1. Change the folder name of database/seeds to database/seeders.

  2. Update composer.json like below:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "database/factories/",
        "Database\\Seeders\\": "database/seeders/"
    }
},
  1. Finally, run the below commands:
composer dump-autoload
php artisan db:seed