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 dumpautoload
and try php artisan db:seed
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
));
}
}
remove your namespace definition in two classes, and use "composer dump-autoload".
Then it will works fine.
Solved: by adding
namespace database\\seeds;
and then running command:
composer dump-autoload --no-dev
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/"
}
},
Also make sure database folder exist inside your project. If you accidently delete the database folder and run migration command. You will get this error too.
只需要进行一次更改,将文件夹种子重命名为播种机。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.