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")
Laravel Seeding Creating a Seeder To create seeders, you may use the make:seeder Artisan command. All seeders generated will be placed in the database/seeds directory. Generated seeders will contain one method: run . You may insert data into your database in this method.
Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.
use Undo Seeder for Laravel. When you install UndoSeeder, the following artisan commands are made available: db:seed-undo Undo seeds in the seeds directory. db:seed-refresh Undo seeds run seeds again.
Laravel offers a tool to include dummy data to the database automatically. This process is called seeding. Developers can add simply testing data to their database table using the database seeder. It is extremely useful as testing with various data types allows developers to detect bugs and optimize performance.
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
For Laravel 8 you need to make the below changes to an existing project for seeding to work:
<?php
namespace Database\Seeders;
Change the folder name of database/seeds
to database/seeders
.
Update composer.json like below:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
composer dump-autoload
php artisan db:seed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With