N
N
Nikolai Vasin2019-07-13 11:39:59
Laravel
Nikolai Vasin, 2019-07-13 11:39:59

How to do data seeding (Database: Seeding) in the database?

Initial data:
PHP 7.2.20
Laravel 5.7.28
1. I run the php artisan make:seeder RolesTableSeeder command
2. The database/seeds/RolesTableSeeder.php file is created

use Illuminate\Database\Seeder;

class RolesTableSeeder extends Seeder
{
    public function run()
    {
        //Метод run специально оставляю пустым, чтобы легче было дебажить
    }
}

3. I run php artisan db:seed
As a result, the error: Class DatabaseSeeder does not exist
composer dump-autoload ran
5d2998d43c8a9655800788.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dk-web, 2019-07-13
@talam0nal

php artisan db:seed runs the database\seeds\DatabaseSeeder.php file that comes out of the box.

<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
      public function run()
    {
       $this->call(RolesTableSeeder::class);
    }
}

if you need a specific seeder to run, you need to set a flag.
php artisan db:seed --class=RolesTableSeeder

K
kafkiansky, 2019-07-13
@mad_maximus

php artisan db:seed --class=RolesTableSeeder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question