Laravel inserting multiple records in table
You can insert multiple records into table at a time in laravel.
Syntax for laravel inserting multiple records in table
DB::table('table_name')->insert(array('data_array1','data_array2'....));
Laravel inserting multiple records in table Example
DB::table('users')->insert(array( array("id"=>'1',"name"=>"john","email"=>"john@testgmail.com"), array("id"=>'2',"name"=>"Jimmi","email"=>"jimmn@testgmail.com"), array("id"=>'3',"name"=>"Kelly","email"=>"kelly@testgmail.com"), array("id"=>'4',"name"=>"Mike","email"=>"mike@testgmail.com"), array("id"=>'5',"name"=>"Steve","email"=>"steve@testgmail.com"), );
or You can also use this :
$data1 = array("id"=>'1',"name"=>"john","email"=>"john@testgmail.com"); $data2 = array("id"=>'2',"name"=>"Jimmi","email"=>"jimmn@testgmail.com"); $data3 = array("id"=>'3',"name"=>"Kelly","email"=>"kelly@testgmail.com"); $data4 = array("id"=>'4',"name"=>"Mike","email"=>"mike@testgmail.com"); $data5 = array("id"=>'5',"name"=>"Steve","email"=>"steve@testgmail.com"); DB::table('users')->insert(array($data1,$data2,$data3,$data4,$data5,));
Advertisements