ReflectionException in Laravel 5 When Seeding Database (Class Does not Exist)

2015-03-17 Laravel

It took me a while to realize what is going on with this strange issue. You did a migration that worked fine? Then you wanted to populate newly created table by seeding your database? You made a proper file, you called the file inside DatabaseSeeder.php using exactly the same class name as in the recent seeding file? You’re absolutely sure that everything is named as it should be and all files exist in a proper place?

So after

php artisan migrate

you run

php artisan db:seed

and you get ReflectionException with irrational message that mentioned class does not exist?

laravel_seed_reflection_exception_01

After migration and before seeding all you have to do is run one additional command. Simply dump autoloads

composer dump-autoload

and then again run seed command

php artisan db:seed

laravel_seed_reflection_exception_02

Everything should work right now as expected. No exceptions and fully populated database. I hope that this hint saved your time. Don’t forget to leave a feedback in the comments section if you have any questions or concerns about Laravel.