so I am creating a seeder in laravel 6.1 but I keep getting this error Illuminate\\Contracts\\Container\\BindingResolutionException : Target class [AdminsTableSeeder] does
Make sure your AdminsTableSeeder.php
file is in the same directory where you have your DatabaseSeeder.php
file.
Run
composer dump-autoload
then try
php artisan db:seed
Optional.
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run(){
$this->call('AdminsTableSeeder');
}
}
try with $this->call('AdminsTableSeeder');
like this.
In your case, move all seeder files from previous database/seeds
directory to database/seeders
folder & then run composer dump-autoload
.
laravel 8
seeders and factories are namespacedTo accommodate for these changes,
[1] - Add Database\Seeders
namespace to your seeder classes.
namespace Database\Seeders;
[2] - Move all seeder files to database/seeders
folder.
[3] - If you import any seeders classes in DatabaseSeeder
file then remove all of them. (simply remove all lines that started with use Database\Seeders\...
from DatabaseSeeder.php)
[4] - Finally run dump-autoload
.
composer dump-autoload
You can now try a fresh migration with seed,
php artisan migrate:fresh --seed
In my case the target Controller class was missing the following line
use Illuminate\Http\Request;