I've upgraded to Laravel 8, but my custom seeder in a subdirectory is not working. The file is at database/seeders/tests/TestSeeder.php.
When I run the command php artisan db:seed --class="TestSeeder"
it return an error message:
Target class [Database\Seeders\TestSeeder] does not exist.
Seeder
<?php
namespace Database\Seeders\Tests;
class TestSeeder extends BaseSeeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// codes
}
}
composer.json
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/",
"Database\\Seeders\\Tests\\": "database/seeders/tests/"
}
},
Laravel assumes you are running a seeder from the Database\Seeders\DatabaseSeeder
class. If you provide an unqualified class name such as TestSeeder
, it will assume you mean the Database\Seeders\TestSeeder
class.
So, you should specify the fully qualified class name.
php artisan db:seed --class="Database\\Seeders\\Tests\\TestSeeder"