laravel eloquent bulk insert code example

Example 1: insert batch in laravel

$data = [
  ['name' => 'John', 'age' => 25],
  ['name' => 'Maria', 'age' => 31],
  ['name' => 'Julia', 'age' => 55],
];
DB::table('table_name')->insert($data);

Example 2: laravel eloquent bulk insert

$data = array(
    array('name'=>'Coder 1', 'rep'=>'4096'),
    array('name'=>'Coder 2', 'rep'=>'2048'),
    //...
);

Coder::insert($data);

Example 3: insert batch in laravel

$data = array(
    array('name'=>'Coder 1', 'rep'=>'4096'),
    array('name'=>'Coder 2', 'rep'=>'2048'),
    //...
);

Coder::insert($data);

Tags:

Php Example