相关文章推荐
开心的山羊  ·  在 SSM ...·  1 年前    · 
越狱的大脸猫  ·  Can't connect to ...·  1 年前    · 
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 Laravel 5 - artisan seed [ReflectionException] Class SongsTableSeeder does not exist (14 answers)
Closed 1 year ago .

I have database seeder clases in diferent folder. When i write db:seed the console shows this error:

[ReflectionException]   Class DatabaseSeeder does not exist , Laravel Seeder

One class is this:

namespace Database\Seeds;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use TiposCompromisosTableSeeder;
class DatabaseSeeder extends Seeder {
     * Run the database seeds.
     * @return void
    public function run()
            Eloquent::unguard();
            $this->call('TiposCompromisosTableSeeder');

and my other class is

namespace Database\Seeds;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class TiposCompromisosTableSeeder extends Seeder{
    public function run(){
        DB::table('tipos')->insert(array(
            'nombre' => 'prioridad',
            'tabla' => 'compromisos',
            'str1' => 'baja',
            'int1' => 1

I've tried to use

composer dump-autoupload 

but doesn't work.

As you can see, I have both clases in the same namespace.

Help please.

If you've recently upgraded your Laravel version, check your composer.json

Your "autoload" section should look something like the snippet below

NOTE: you may have to add the "database" entry under the "classmap"

"autoload": {
        "classmap": [
          "app/Library",
          "app/Models",
          "database"
        "psr-4": {
            "App\\": "app/"
        "files": [
            "app/Library/helpers.php"

You should then run composer dump-autoload and try php artisan db:seed

Great ... after add this line into composer and run composer i everything OK and errors gone forever ;) Thank you – saber tabatabaee yazdi Mar 2, 2020 at 12:58 Adding this change and running composter dump-autoload didn't work for some reason, but worked after I ran composer install. – xyz Mar 21, 2022 at 9:37

You should add this line into composer.json file inside "psr-4":

"Database\\Seeders\\": "database/seeders/"

it means that should be something like:

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Modules\\": "Modules/",
        "Database\\Seeders\\": "database/seeders/"

Just put it all in the DatabaseSeeder.php file like this:

use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder {
     * Run the database seeds.
     * @return void
    public function run()
            Eloquent::unguard();
            $this->call('TiposCompromisosTableSeeder');
class TiposCompromisosTableSeeder extends Seeder{
    public function run(){
        DB::table('tipos')->insert(array(
            'nombre' => 'prioridad',
            'tabla' => 'compromisos',
            'str1' => 'baja',
            'int1' => 1
                The Laravel code I have in the latest install doesn't have the DatabaseSeeder class in a namespace.   If you're going to name space it, as well as the other class, you may need to register them in the IoC container before artisan can find them.   Artisan uses the DatabaseSeeder class by default, which it finds without the namespace.   It would just be much easier leaving it as is and put your other classes in the same file below it, so they can be found without having to register them (which I'm not even sure will work from the console).
– Brian H.
                May 23, 2015 at 4:58
                @ricardovigatti it is the solution. Laravel seeds have no namespace, therefore the CLI command db:seed will have no reference to a namespace, just a class in the root. However, multiple classes / file is not good.
– David Barker
                Aug 1, 2017 at 16:21