Illuminate\Contracts\Container\BindingResolutionException
Target class [Database\Seeders\CountriesTableSeeder] does not exist.
at C:\......\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php:811
807▕
808▕ try {
809▕ $reflector = new ReflectionClass($concrete);
810▕ } catch (ReflectionException $e) {
➜ 811▕ throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
812▕ }
813▕
814▕ // If the type is not instantiable, the developer is attempting to resolve
815▕ // an abstract type such as an Interface or Abstract Class and there is
1 C:\......\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
ReflectionException::("Class Database\Seeders\CountriesTableSeeder does not exist")
2 C:\......\blog\vendor\laravel\framework\src\Illuminate\Container\Container.php:809
ReflectionClass::__construct("Database\Seeders\CountriesTableSeeder")

- 3,844
- 5
- 20
- 43

- 149
- 1
- 1
- 3
-
It can't find your seeder called `CountriesTableSeeder`. Try `composer dump-autoload -o` and then rerun. Also you should provide some code showing us how the seeder is defined, etc. – PatricNox Sep 29 '20 at 09:25
-
i was tried the composer dump-autoload -o command , but not working. – Ali Hussain Qumar Sep 29 '20 at 09:35
10 Answers
For Laravel 8 you need to make the below changes to an existing project for seeding to work:
- Add the Database\Seeders namespace to your DatabaseSeeder.php and other seeder files :
<?php
namespace Database\Seeders;
Change the folder name of
database/seeds
todatabase/seeders
.Update composer.json like below:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
- Finally, run the below commands:
composer dump-autoload
php artisan db:seed

- 2,771
- 2
- 17
- 31
-
1namespace Database\Seeders; Add this on the top of CreateUsersSeeders.php helped me. – Christopher Nolan Jul 06 '21 at 05:42
-
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

- 1,879
- 14
- 20
-
3I actually couldn't find this change in the upgrade guide, so this saved me some time, thanks – nsbucky Oct 09 '20 at 14:53
-
-
Also don't forget to update composer autoload to "classmap": [ "database/seeders" ] – Sule-balogun O.G Mar 24 '22 at 15:03
working with laravel 8
change directory name database/seeds to database/seeders.
add namespace Database\Seeders; to seeders file.
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class TableSeeder extends Seeder{
}
Update Compose.json file
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}},
run in terminal
composer dump-autoload
php artisan db:seed --class=TableSeeder

- 559
- 9
- 17
When working with new seeders we might get
Target class [...TableSeeder] does not exist.
In my case, simply running
composer dump-autoload
did the trick

- 42,008
- 16
- 111
- 154

- 14,289
- 18
- 86
- 145
remove using TableSeeder
at the top of the DatabaseSeeder.php file.

- 77
- 1
- 4
-
1I tried all the methods in this thread but none of them worked for me. Then I remove the above mentioned line and it worked well for me. – Dulanjana_Bandara Jul 23 '21 at 05:51
DatabaseSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
CountriesTableSeeder::class,
ProvincesTableSeeder::class,
RegionsTableSeeder::class,
PermisionsTableSeeder::class,
RolesTableSeeder::class,
StatusTypesTableSeeder::class,
StatusesTableSeeder::class,
]);
}
}
CountriesTableSeeder.php
<?php
use App\Country;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
class CountriesTableSeeder extends Seeder
{
private $numberOfCountries = 10;
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('countries')->insert([
['country_name' => 'iraq'],
['country_name' => 'qater'],
]);
}
}

- 149
- 1
- 1
- 3
After running: composer dump:autoload
I could just include the below code in my DatabaseSeeder
and It would include the data from SubsidyregimeTableSeeder
$this->call([
SubsidyregimeTableSeeder::class
]);

- 8,413
- 7
- 27
- 35
In my case, I had an existing code of version 5.8 of Laravel.
So the files were duplicated in Seeds
folder, the namespace was missing in and I had to reinstall Voyager with dummy like so :
composer dump-autoload
php voyager:install --with-dummy
fixed the namespace to namespace Database\Seeders;
instead of namespace Database\Seeds;

- 518
- 6
- 16
- Rename directory database/seeds to database/seeders
- Open composer.json file and change on autoload section.
"autoload": { "psr-4": { "App\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
}
- Open Database Seeder file database/seeders/DatabaseSeeder.php and add namespace Database\Seeders; on top of page.
- Open your others seeders file and add namespace Database\Seeders; to all seeders class.
- Run composer dump-autoload and php artisan migrate:fresh --seed

- 1
- 1
Remember if you upgrade ti laravel 8 you need to change directory name database/seeds to database/seeders.

- 53
- 8