How to insert multiple rows in database Laravel 5?


If you want to create multiple records at time using laravel eloquent, then you can do it using "insert()" of laravel eloquent. insert() will provide to bulk insert records. insert() take array argument. You can simply give array then it will create single rows of table, if you pass multi dimensional array, then will create multiple records.

Here, you can learn to insert several records at time, as bellow i give you syntax of insert().

Syntax:

DB::table('yourTableName')

->insert(array(

array(...),

array(...),

array(...),

.....

));

As above syntax, you can see how to pass multiple records for insert, So, let's see bellow example.

Example:

DB::table('items')

->insert(array(

array('title'=>'Test', 'description'=>'Test Description'),

array('title'=>'Test 2', 'description'=>'Test Description 2'),

array('title'=>'Test 3', 'description'=>'Test Description 3'),

));

If you want to insert multiple records then it can help you...


April 19, 2017 | 2114 Viewer | Category : Laravel
Related Posts:



Blog Search