Home > Software design >  Seeder does not put anything in Mysql database
Seeder does not put anything in Mysql database

Time:06-26

Hi everyone. When I run php artisan db:seed 2 other seeders does work, in this one I have error inserting 3 new vaulues into empty table, if someone have better eyes than me; code is below :

> <?php
> 
> namespace Database\Seeders; use App\Models\Cars; use
> Illuminate\Database\Seeder; use Illuminate\Support\Str; use
> Illuminate\Support\Facades\DB;
> 
> class CarSeeder extends Seeder {
>     /**
>      * Run the database seeds.        ne radi ispod
>      *
>      * @return void
>      */
>     public function run()
>     {
>         Cars::table('cars')->insert([
>             'id'=>increment(),
>             'marka'=>'BMW',
>             'tip'=>'karavan'
>             
>         ]);
>         Cars::table('cars')->insert([
>             'id'=>increment(),
>             'marka'=>'Toyota',
>             'tip'=>'coupe'
>             
>         ]);
>         Cars::table('cars')->insert([
>             'id'=>increment(),
>             'marka'=>'Mercedes',
>             'tip'=>'limuzina'
>             
>         ]);
>     } }

CodePudding user response:

You should call it like so:

php artisan db:seed --class=CarSeeder

Or your seeder should be registered in database/seeders/DatabaseSeeder.php:

$this->call([
    CarSeeder::class
]);
  • Related