n1215 / eloquent-bulk-save
bulk insert multiple records using Eloquent Model.
Installs: 16 374
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: >=7.0.0
- illuminate/database: ^5.6
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is auto-updated.
Last update: 2024-12-19 13:58:58 UTC
README
This library contains a trait that enables \Illuminate\Database\Eloquent\Model to bulk insert multiple records in one query. Unlike in the case of directly using \Illuminate\Database\Query\Builder::insert(), this trait method fires each eloquent model events like eloquent.creating, eloquent.saving, and so on.
Usage
// 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);
License
The MIT License (MIT). Please see LICENSE for more information.