ReflectionException - Class DatabaseSeeder does not exist , Laravel Seeder

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.


ANSWERS:


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 dumpautoload and try php artisan db:seed


Solved: by adding

namespace database\seeds;

and then running command:

composer dump-autoload --no-dev


Does adding the --no-dev flag help?

composer dump-autoload --no-dev

source


remove your namespace definition in two classes, and use "composer dump-autoload".

Then it will works fine.


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
        ));
    }
}


 MORE:


 ? ReflectionException - Class DatabaseSeeder does not exist , Laravel Seeder
 ? ReflectionException - Class DatabaseSeeder does not exist , Laravel Seeder
 ? Laravel | ReflectionException - Class does not exist
 ? Laravel | ReflectionException - Class does not exist
 ? Laravel | ReflectionException - Class does not exist
 ? How to load my own code into Laravel? Differences between those ways?
 ? Class 'Role' not found
 ? Laravel 4 custom package not appearing in autoload_namespace.php
 ? Laravel 5 - Creating Artisan Command for Packages
 ? Laravel 5 - Creating Artisan Command for Packages