Forum

Laravel, Seeder sim...
 
Notifications
Clear all

Laravel, Seeder simple example

1 Posty
1 Users
0 Reactions
637 Widok
0
Topic starter

an simple seeder example

1 Answer
0
Topic starter
<?php

namespace Database\Seeders;

use App\Models\MyModelType;
use Illuminate\Database\Seeder;

class MyModelTypeSeeder extends Seeder
{
    public function run()
    {
        $data = array(
            ['id' => 1,'name' => 'example name 1'],
            ['id' => 100,'name' => 'example name 2'],
            ['id' => 3,'name' => 'example name 3'],
        );

        foreach ($data as $item) {
            try {
                MyModelType::create($item);
            } catch (\Exception $e){
                dd($e);
            }
        }
    }
}

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: