Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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:
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:
// 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);
You need to put SongsTableSeeder into file SongsTableSeeder.php in the same directory where you have your DatabaseSeeder.php file.
And you need to run in your console:
composer dump-autoload
to generate new class map and then run:
php artisan db:seed
I've just tested it. It is working without a problem in Laravel 5
–
–
–
Remove file.
Run command: php artisan make:seeder .
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.
–
–
–
–
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
php artisan db:seed --class=SongsTableSeeder
–
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'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.
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"
When you migrate your project to Laravel 8 and you get that error then you should follow some steps given below.
1.Go to your composer.json file.
2.Change autoload section
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
"autoload": {
"psr-4": {
"App\\": "app/"
"classmap": [
"database/seeds",
"database/factories"
3.Now run the command of composer dump-autoload or composer update
4.And last run command of php artisan db:seed
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!
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)]);
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!
–