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...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example