How to Bulk in Laravel using eloquent ORM

BOOKC, this time share about How to Bulk in Laravel using eloquent ORM

How can we perform bulk database insertions in Laravel using Eloquent ORM ?

Laravel can bulk insertion using eloquent ORM. Insertion is the very basic feature in all project. When we need to do bulk insertion there is a lot of ways are available in Laravel to do the bulk insertion. Some of the ways to bulk insertion are:

1) By using the Raw query in Laravel.

2) By using eloquent ORM.

Example of using eloquent ORM bulk insertion

You can just use Users::insert().

$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);

Hopefully this article can solve the problem in working on your project. Thank you

Bookc
Admin

Hopefully the information we provide can be useful.

Press ESC to close