Insertion is the very basic feature in every project. When we want to do bulk insertion there are n number of ways are available in Laravel to do bulk insertion. Some of the way to bulk insertion are:
1) By using Raw query in Laravel.
2) By using eloquent.
By using Eloquent bulk insertion syntax is:
Syntax:
Eloquent::insert()
Example of Eloquent bulk insertion
$data = array(
array(
'name'=>'Coder 1', 'rep'=>'4096',
'created_at'=>date('Y-m-d H:i:s'),
'modified_at'=> date('Y-m-d H:i:s')
),
array(
'name'=>'Coder 2', 'rep'=>'2048',
'created_at'=>date('Y-m-d H:i:s'),
'modified_at'=> date('Y-m-d H:i:s')
),
//...
);
User::insert($data);
Here in the above example User is a eloquent and array data is bulk which we want to insert data.
By this way we can do bulk insertion.
0 Comment(s)