[laravel] Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist

When I run php artisan db:seed I am getting the following error:

[ReflectionException] Class SongsTableSeeder does not exist

What is going on?

My DatabaseSeeder class:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call('SongsTableSeeder');
    }

}

My SongsTableSeeder class:

<?php

// Composer: "fzaninotto/faker": "v1.4.0"
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;
use DB;

class SongsTableSeeder extends Seeder {

    public function run()
    {
        $faker = Faker::create();
        $songs = [];
        foreach(range(1, 10) as $index)
        {
            $songs[] = ['title' => $faker->words(rand(1,4))];
        }

        DB::table('songs')->insert($songs);

    }

}

This question is related to laravel composer-php laravel-5 laravel-artisan

The answer is


If you migrated to Laravel 8, you have to add a namespace to the seeders class:

<?php

namespace Database\Seeders;

...

Next, in your composer.json file, remove classmap block from the autoload section and add the new namespaced class directory mappings:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Seeders\\": "database/seeds/"
    }
},

An finally, do a composer dump-autoload.

For more information: https://laravel.com/docs/8.x/upgrade#seeder-factory-namespaces


I solved it by doing this:

  1. Copy the file content.
  2. Remove file.
  3. Run command: php artisan make:seeder .
  4. Copy the file content back in this file.

This happened because I made a change in the filename. I don't know why it didn't work after the change.


I'm running the very latest Laravel 5 dev release, and if you've changed the namespace you'll need to call your seed class like this:

$this->call('\todoparrot\TodolistTableSeeder');

Obviously you'll need to replace todoparrot with your designated namespace. Otherwise I receive the same error indicated in the original question.


i got [ReflectionException] Class Seeder does not exist too and when i use composer dump-autoload, i got an error preg_match(): JIT compilation failed: no more memory when i run it.

What i did is that i change ;pcre.jit=1 to pcre.jit=Off in php.ini! You can find the path by using php --ini in your terminal!

I am using mac with php 7.3! Hope that help any of you guys out there!


If you have copied the seeders files from any other project then you need to run the artisan command php artisan db:seed otherwise it is fine.


I have used only SINGLE FILE with TWO classes in it following :

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Lesson;

use Faker\Factory as Faker;

class DatabaseSeeder extends Seeder {

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    //Lesson::truncate();

    Model::unguard();

    $this->call("LessonsTableSeeder");


}

}

class LessonsTableSeeder extends Seeder {

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{

    $faker = Faker::create();

    foreach(range(1,30) as $index) {

        Lesson::create(['title' => $faker->sentence(5), 'body' => $faker->paragraph(4)]);

    }

}

}

If our CustomTableSeeder is in same directory with DatabaseSeeder we should use like below:

$this->call('database\seeds\CustomTableSeeder');

in our DatabaseSeeder File; then another error will be thrown that says: 'DB Class not found' then we should add our DB facade to our CustomTableSeeder File like below:

use Illuminate\Support\Facades\DB;

it worked for me!


SongsTableSeeder.php should be in database/seeds directory

Console command steps:

composer dump-autoload

and then:

php artisan cache:clear

and then:

php artisan optimize

and then:

php artisan db:seed

or:

php artisan db:seed --class=SongsTableSeeder

You probably specify the .php extension and It don't found your class.

What I was doing :

php artisan db:seed --class=RolesPermissionsTableSeeder.php

What solved my problem : What I was doing :

php artisan db:seed --class=RolesPermissionsTableSeeder

File SongsTableSeeder.php should be in database/seeds directory or in its subdirectory.

You need to run:

composer dump-autoload

and then:

php artisan db:seed

or:

php artisan db:seed --class=SongsTableSeeder

Do not forgot that the composer dump-autoload works in relation with the autoload / classmap section of composer.json. Take care about that if you need to change seeders directory or use multiple directories to store seeders.

"autoload": {
    "classmap": [
      "database/seeds",
      "database/factories"
    ],
},

I had the same "reflection exception" error. The solution was to copy the class file to the server, from dev, for me. dumb mistake, but given how many files we deal with its easy to forget to copy them over to the server every time.


Examples related to laravel

Parameter binding on left joins with array in Laravel Query Builder Laravel 4 with Sentry 2 add user to a group on Registration Target class controller does not exist - Laravel 8 Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Post request in Laravel - Error - 419 Sorry, your session/ 419 your page has expired Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required How can I run specific migration in laravel Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

Examples related to composer-php

Composer require runs out of memory. PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted How to change PHP version used by composer PHP7 : install ext-dom issue PHP error: "The zip extension and unzip command are both missing, skipping." Composer: file_put_contents(./composer.json): failed to open stream: Permission denied require(vendor/autoload.php): failed to open stream How to install a specific version of package using Composer? Composer update memory limit Cannot create cache directory .. or directory is not writable. Proceeding without cache in Laravel To enable extensions, verify that they are enabled in those .ini files - Vagrant/Ubuntu/Magento 2.0.2

Examples related to laravel-5

Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory Can't install laravel installer via composer Including a css file in a blade template? No Application Encryption Key Has Been Specified How to Install Font Awesome in Laravel Mix Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes Laravel 5.4 redirection to custom url after login How to set the default value of an attribute on a Laravel model laravel 5.3 new Auth::routes()

Examples related to laravel-artisan

No Application Encryption Key Has Been Specified Laravel 5.4 create model, controller and migration in single artisan command SQLSTATE[HY000] [2002] Connection refused within Laravel homestead ReflectionException: Class ClassName does not exist - Laravel Artisan, creating tables in database Laravel 5 Clear Views Cache Laravel 5 How to switch from Production mode Could not open input file: artisan Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist What are the Differences Between "php artisan dump-autoload" and "composer dump-autoload"?