PHP code example of n1215 / eloquent-bulk-save
1. Go to this page and download the library: Download n1215/eloquent-bulk-save library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
n1215 / eloquent-bulk-save example snippets
// 1. change your eloquent model class to use the trait
class YouModel extends \Illuminate\Database\Eloquent\Model
{
use \N1215\EloquentBulkSave\BulkInsert;
}
// 2. create model collection (you can also use Illuminate\Database\Eloquent\Collection)
$models = \Illuminate\Support\Collection::make([
new YourModel($attributes1),
new YourModel($attributes2),
...
]);
// 3. use bulkInsert() static method
YourModel::bulkInsert($models);