Posts Learn Components new Snippets new Categories Tags About
/

How to Fix Laravel Artisan Seed Command Return [ReflectionException] Class Seeder Does not Exist

Learn how to fix class seeder does not exists error in Laravel the easy way

Created on Oct 05, 2021

19 views

Sometimes you might come across ReflectionException when running the seeder mentioning that your seeder doesn't exist. This error actually has several ways to fix and in these snippets, you will get to know one way or the other to fix this error.
php artisan db:seed

Fix 1: Run composer dump-autoload


The easy way to fix this "Class Seeder Does not Exist" error is to run the composer dump-autoload and this command will regenerate the list of all classes that need to be included in the project.
php artisan dump-autoload

Fix 2: Update Namespace For Seeder


If you are not using Laravel 8 then you can update the namespace for the seeder. Below is the seeder namespace and you can reference this namespace from within the composer JSON autoload function.
<?php

namespace Database\Seeders;
The autoload function will be as follows.  Once again do run "composer dump-autoload" to regenerate all of the lists of classes to be included.
"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Seeders\\": "database/seeds/"
    }
},

Fix 3: Specify your Seeder Class


Sometimes you might can just explicitly specify your seeder class and it's like the following. Do note that using this method you will have to run your seeder one by one.
php artisan db:seed --class=UsersTableSeeder
new

If you like our tutorial, do make sure to support us with some coffee. We need the juice to write the content during the night 🤙🏻