Download the PHP package laravel-macros/eloquent-insert-as-model without Composer
On this page you can find all versions of the php package laravel-macros/eloquent-insert-as-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download laravel-macros/eloquent-insert-as-model
More information about laravel-macros/eloquent-insert-as-model
Files in laravel-macros/eloquent-insert-as-model
Package eloquent-insert-as-model
Short Description Add `insertAsModel` macro to Eloquent Builder. Unlike `insert`, `insertAsModel` method will ensure that all inserted values will go through models' casts and mutators.
License MIT
Homepage https://github.com/laravel-macros/eloquent-insert-as-model
Informations about the package eloquent-insert-as-model
Laravel Macros: Eloquent | insertAsModel
This package will add insertAsModel
macro to Laravel's Eloquent Builder class.
Unlike insert
, insertAsModel
method will ensure that all inserted values will go through models' casts and mutators then it will just pass it to the insert
method.
Installation
You can install the package via composer:
Usage
Assuming you have:
Normally if you will use the Model::insert
method to insert a batch of entries, casts and mutators will be ignored and you will have to stringify the values yourself.
Using this package, you can insert values the same way you use Model::create
, where all the proper casting and mutating logic will be applied.
This will prevent you from doing hacks like 'options' => json_encode(['sms' => true])
.
Note:
insertAsModel
is not a multiplecreate
calls. It will insert entries directly to the database (just likeinsert
). For example it won't fire models events.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Mohannad Najjar
- All Contributors
License
The MIT License (MIT). Please see License File for more information.