A
A
Artem2020-07-29 14:03:46
Composer
Artem, 2020-07-29 14:03:46

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

I am using 1 seed file:
<?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'),
        ]);
...

my composer.json:
"autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },

most likely a problem with "database/seeds", (if so, please tell me what to do about it).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton October, 2020-07-29
@artem_atlas

First, execute composer dump-autoloadonce 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 question

Ask a Question

731 491 924 answers to any question