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

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

896

3 years ago

0 comments

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
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this