After upgrading to Laravel 8 from latest Laravel 7,
Seeder doesn't work if I specify --class=.. option.
Without specifying --class,
php artisan db:seed
can run.
php artisan make:seeder AdditionalJobAttrSeeder;
php artisan db:seed --class=AdditionalJobAttrSeeder;
In Container.php line 811:
Target class [Database\Seeders\AdditionalJobAttrSeeder] does not exist.
In Container.php line 809:
Class Database\Seeders\AdditionalJobAttrSeeder does not exist
I could resolve this problem by editing
vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php
by commenting out
if (strpos($class, '\\') === false) {
// $class = 'Database\\Seeders\\'.$class;
}
which means I can resolve the issue by typing
php artisan db:seed --class=\\AdditionalJobAttrSeeder;
even if I don't edit the file but this is different behavior from official document and previous behavior.
So actually
https://github.com/laravel/framework/commit/cadad245ff1d5e294ef6d3f312d66dc63f728619
brought this bug.
Did you add the new namespaces? https://github.com/laravel/laravel/blob/master/database/seeders/DatabaseSeeder.php#L3
And register them in your composer.json? https://github.com/laravel/laravel/blob/master/composer.json#L39
And ran composer dump
?
Thanks for you comment.
compser.json and composer dump were done.
but
Did you add the new namespaces?
Seed Class was created in Laravel 7.25 by "php artisan make:seeder ..." and at the time it doesn't have the namespace but it worked.
But I noticed that if I create seed class in 8.0.0 from zero using "php artisan make:seeder TestSeeder", it now adds namespace.
So the problem is SeederClass created by lalavel 7 lost compatibility with Laravel 8 without changing the code if we specify --class=... option.
If it is described in https://laravel.com/docs/8.x/upgrade as compatibility problem, it would be better but I think the solution is clear now.
Same problem here and that's how I fixed:
Update composer.json and add namespaces to seeders as mentioned in https://github.com/laravel/framework/issues/34243#issuecomment-690094980
Rename database/seed directory to database/seeders.
As hikarine3 said would be nice to have this compatibility issue mentioned in the upgrade guide.
Thanks!
Thanks. I've sent in a PR here: https://github.com/laravel/docs/pull/6339
I have derictories into "seeders". If i write psr-4 namespase for folder, - error target class [Database\Seeders\SafeSeeder] does not exist
namespace Database\Seeders\Safe;
If I am correct,
php artisan make:seeder TestSeeder
will create the file under
database/seeds
yet even in Laravel 8.0.0, so writing
"Database\\Seeders\\": "database/seeders/"
doesn't match with default location, I am afraid.
It should be
"Database\\Seeders\\": "database/seeds/"
or the location of creation of "php artisan make:seeder ..." should be changed.
Hello,
I executed(With Laravel 8.0.3) php artisan make:seeder TestSeeder and it created the file under database/seeders with the namespace Database\Seeders
so it's working fine for me :)
Hmm, then I guess
grep -r seeds vendor/laravel/framework
vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeederMakeCommand.php: if (is_dir($this->laravel->databasePath().'/seeds')) {
vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeederMakeCommand.php: return $this->laravel->databasePath().'/seeds/'.$name.'.php';
affected the difference of behavior (Laravel 8.0.4).
So if we remove "database/seeds" directory, I think the behavior of creation of class will change like you said.
So either way is O.K in code's perspective but we should set correct path in composer.json depending on existence of dastabase/seeds directory.
Yeah, I have assumed you followed my steps form here https://github.com/laravel/framework/issues/34243#issuecomment-690112896 馃槄
I haven't tried, but maybe you can change the default seeder stub and put the old seeds path in the composer.json, so then you don't need to change the directory name ( I didn't tested this!)
Either can be O.K but changing like you would be better considering it is default location in Laravel 8 though we don't see change if we haven't renamed database/seeds directory.
I'm using Laravel 8.6.0, created a seeder, it includes the namespaces by default, and the files are put in the database/seeders directory, but still cant find my seeder, even after running composer dump-autoload :
Illuminate\Contracts\Container\BindingResolutionException
Target class [CoursesTableSeeder] does not exist.
sorry to zombify this thread, but I have followed the steps indicated on comment #34243 and still have the same issue described by @ekosynth and @hikarine3 on previous comments:
Illuminate\Contracts\Container\BindingResolutionException
Target class [Database\Seeders\CoursesTableSeeder] does not exist.
at vendor/laravel/framework/src/Illuminate/Container/Container.php:811
Any ideas on how to solve this?
It still not working, Laravel 8.10.0, checked everything described in this thread
UPD
Ok, I have made like this:
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
Most helpful comment
I'm using Laravel 8.6.0, created a seeder, it includes the namespaces by default, and the files are put in the database/seeders directory, but still cant find my seeder, even after running composer dump-autoload :