Home:ALL Converter>Laravel: Update multiple rows in one query

Laravel: Update multiple rows in one query

Ask Time:2018-08-29T11:31:37         Author:hayumi kuran

Json Formatter

How can i update multiple rows use laravel eloquent?

I want something like:

$guest = GuestJointDetail::where('guest_joint_id', $guest_joint_id)
    ->where('sort_no', '>', $sort_no)
    ->whereNull('deleted_at');

$guest->update(['sort_no' => DB::raw('sort_no - 1')]);

I have tried

$guest->update(['sort_no' => 10]);

and i worked!
So i think my problem is in DB::raw

Thank you so much!

Author:hayumi kuran,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52069062/laravel-update-multiple-rows-in-one-query
Dhruv Raval :

use decrement();\n\nguest = GuestJointDetail::where('guest_joint_id', $guest_joint_id)\n ->where('sort_no', '>', $sort_no)\n ->whereNull('deleted_at')\n ->decrement('sort_no',1);\n\n\nuse whereIn for multiple Ids:\n\nguest = GuestJointDetail::whereIn('guest_joint_id', $guest_id_array)\n ->where('sort_no', '>', $sort_no)\n ->whereNull('deleted_at')\n ->decrement('sort_no',1);\n",
2018-08-29T03:58:28
yy