php

Laravel – artisan seed [ReflectionException] Class OrganizationSeeder does not exist

Problem

When I ran my php artisan db:seed I got the following error:

[ReflectionException] Class OrganizationSeeder 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('OrganizationSeeder');
    }

}

My OrganizationSeeder class:

<?php

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

class OrganizationSeeder extends Seeder {

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

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

    }

}

Solution

You need to put
OrganizationSeeder into file
OrganizationSeeder.php in the same directory where you have your
DatabaseSeeder.php file.

This is a common issue, especially if you just created that file by hand. What’s more important that your composer probably didn’t get updated with the new class. And you need to run in your console:

composer dump-autoload

to generate new class map and then run:

php artisan db:seed

It is working without a problem in Laravel

About the author

laravelrecipies