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.
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/"
}
},
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
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
));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With