Write in front
Everyone who is familiar with laravel knows that laravel has Multiple records are inserted in batches at one time, but multiple records are not updated conditionally at one time.
Do you envy thinkphp's saveAll, do you envy ci's update_batch, but why does such an elegant laravel not have a similar batch update method?
Experts Googled the folk
and found that someone had already written on stackoverflow (https://stackoverflow.com/questions/26133977/laravel-bulk-update) Okay, but it doesn't prevent sql injection.
This article has been adjusted in conjunction with laravel's Eloquent to effectively prevent sql injection.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
You can make adjustments according to your own needs. The following is a usage example:
1 2 3 4 5 6 7 8 |
|
The generated SQL statement is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Is the efficiency improved a lot? Well~
Related recommendations:The latest five Laravel video tutorials