Eloquent batch update multiple records
Instead of batch assigning values to multiple fields in one record,
but making different modifications to different records according to different conditions
.
Similar to batch insert:
DB::table('users')->insert(array(
array('email' => 'taylor@example.com', 'votes' => 0),
array('email' => 'dayle@example.com', 'votes' => 0),
));
Is there any similar statement
DB::table('users')->update( array(
array('id'=>1, 'email' => 'taylor1@example.com', 'votes' => 1),
array('id'=>2, 'email' => 'dayle2@example.com', 'votes' => 2),
) , 'id' );
The functions implemented are:
Modify the corresponding record according to the id:
id=1 'email' is changed to 'taylor1@example.com', 'votes' is changed to 1,
id=2 'email' is changed to 'dayle2@example.com', 'votes' is changed to 2
. . .
CI has a similar update_batch method. I want to convert it to laravel. Please give me more advice.
There is currently no good way to encapsulate the framework, but I just googled it and saw an answer that matches your question very well on stackoverflow. The following is copied from stackoverflow, the original link is http://stackoverflow.com/questions/ 26133977/laravel-bulk-update.
I have created My Custom function for Multiple Update like update_batch in CodeIgniter.
Just place this function in any of your model or you can create helper class and place this function in that class:
It will Produces: