“Masukkan data menggunakan seeder di Laravel” Kode Jawaban

Masukkan data dalam database menggunakan seeder di Laravel

step-1- php artisan make:seeder yourSeedername
step-2- //add data in inside run function in your new created seeder. eg
        $Records = [
            ['id'=>1, 'name'=>'abc','email'=>'[email protected]'],
            ['id'=>2, 'name'=>'xyz','email'=>'[email protected]']
        ];
        YourModel::insert($Records);
        //don't forget to use model in top of your seeder
step-3- //register seeder in run function inside Database/Seeders/DatabaseSeers.php as follows
        $this->call(yourseeder::class);
step-4- //Now run following command
        php artisan db:seed
Isaac

cara membuat db seeder di laravel

php artisan make:seeder UsersTableSeeder
MrDracoula

Masukkan data menggunakan seeder di Laravel

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
...
...
DB::table('users')->insert([
    'name' => 'John Doe',
    'email' => '[email protected]',
    'password' => Hash::make('password')
]);
kinjal suryavanshi

Masukkan data dalam database menggunakan seeder di Laravel 8

php artisan db:seed
Anxious Antelope

Parameter ke Laravel Seeder

class UsersTableSeeder extends Seeder
{
    public function run()
    {
        $limit = env('SEEDER_LIMIT', 1);

        echo $this->limit;
    }
}

//In terminal run:
SEEDER_LIMIT=10 php artisan db:seed --class=UsersTableSeeder
Tiago F2

Jawaban yang mirip dengan “Masukkan data menggunakan seeder di Laravel”

Pertanyaan yang mirip dengan “Masukkan data menggunakan seeder di Laravel”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya