php artisan db:seed cannot find your seeder class
[ReflectionException] Class SongsTableSeeder does not existShort answer
Artisan looks for your seeder through Composer's autoloader. Since Laravel 8 that means a Database\Seeders namespace and the database/seeders folder. On older projects the class must be in Composer's classmap, so composer dump-autoload is needed. Check the namespace line and the autoload block in composer.json first.
Fix it fast
1Find out which cause you have
See which folder holds the seeder and which namespace and autoload rule are in play.
ls database/ head -n 8 database/seeders/SongsTableSeeder.php grep -n -A8 '"autoload"' composer.json2Match what you see, then jump to its fix
- 1
The file sits in database/seeders but starts with <?php and then straight into 'class'The seeder has no Database\Seeders namespace (Laravel 8 and newer)Fix - 2
The folder is database/seeds, and composer.json autoload still has a classmap entryA project upgraded from Laravel 7: database/seeds and the classmap block are still thereFix - 3
The file exists and the name is right, but it was created or copied after the last composer runA new seeder was added to a classmap project and the autoloader was not regenerated (Laravel 7 and older)Fix
- 1
What does the error look like?
[ReflectionException] Class SongsTableSeeder does not exist
Cause 1 of 3
The seeder has no Database\Seeders namespace (Laravel 8 and newer)
1Check
By default db:seed runs Database\Seeders\DatabaseSeeder, and seeders live in database/seeders. A class without the namespace line is not found at its expected name.
grep -n "namespace" database/seeders/*.php2Fix
Add the namespace to every seeder, and make sure composer.json maps it. Then rebuild the autoloader.
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class SongsTableSeeder extends Seeder
{
public function run(): void { /* ... */ }
}3Verify
Run that seeder on its own.
php artisan db:seed --class=SongsTableSeederConfirmed by laravel.com
Cause 2 of 3
A project upgraded from Laravel 7: database/seeds and the classmap block are still there
1Check
Laravel 8 moved seeders to database/seeders with a namespace. The upgrade guide says to rename the folder, add the namespace and replace the classmap block with PSR-4 mappings.
ls -d database/seeds database/seeders
grep -n -E "classmap|Database" composer.json2Fix
Rename the folder, add the namespace to each class, and use these mappings in composer.json. Then dump the autoloader.
git mv database/seeds database/seeders
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
}
composer dump-autoload3Verify
Seed again.
php artisan db:seedConfirmed by laravel.com
Cause 3 of 3
A new seeder was added to a classmap project and the autoloader was not regenerated (Laravel 7 and older)
1Check
Classmap autoloading is built by scanning files, so a new class stays unknown until the map is rebuilt.
composer dump-autoload2Fix
Regenerate the autoloader, then run the seeder. The Laravel 7 seeding page asks for this step after you write a seeder.
composer dump-autoload
php artisan db:seed --class=SongsTableSeeder3Verify
The seeder runs without the ReflectionException.
php artisan db:seed --class=SongsTableSeederConfirmed by laravel.com
How do I stop it coming back?
- Generate seeders with php artisan make:seeder so the namespace and folder are right.
- After copying files in by hand, run composer dump-autoload.
- Keep one seeder per file, with the file name equal to the class name.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
composer require maatwebsite/excel fails to install
Composer says the package needs an older PHP than the one installed
Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.
3 causes, each with a fixBack end
composer install says the lock file is not compatible and asks for update
Your lock file does not contain a compatible set of packages. Please run composer update.
composer install checked the locked packages against this machine's PHP and extensions and found a conflict.
3 causes, each with a fixBack end
composer require laravel/horizon fails: ext-pcntl is missing
laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system
Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.
3 causes, each with a fixBack end
composer require laravel/passport stops with 'requirements could not be resolved'
... but these were not loaded, likely because it conflicts with another require.
Composer found no Passport release that fits your project at once.
4 causes, each with a fixBack end
Composer says the root composer.json requires a PHP version your PHP does not satisfy
Your requirements could not be resolved to an installable set of packages.
Composer compares the php constraint in your composer.json, or in a package, with the PHP that runs Composer.
3 causes, each with a fix