Answer the question
In order to leave comments, you need to log in
How to fix seeder migration error?
I am trying to run php artisan migrate --seed or php artisan db:seed on which I get the error:
Class DatabaseSeeder does not exist
at C:\OSPanel\domains\vs.develop\vendor\laravel\framework\src\Illuminate\Container\Container.php:788
<?php
namespace Database\Seeds;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
'name' => 'admin',
'email' => '[email protected]',
'password' => bcrypt('mypass'),
]);
...
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
Answer the question
In order to leave comments, you need to log in
First, execute composer dump-autoload
once the error indicates that there is no class.
And also in the DatabaseSeeder it is better to call the described seeders, i.e. create classes in the same directory, for example UsersTableSeeder.php and do the logic of filling the database for this table within this class, and then in the DatabaseSeeder in the run method call the class for each table.
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call(UsersTableSeeder::class);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question