Home:ALL Converter>Laravel eloquent update record with minimum value

Laravel eloquent update record with minimum value

Ask Time:2018-08-21T15:55:29         Author:Mohammad_Hosseini

Json Formatter

I need to find the minimum "priority" value and then set it's value to another entry, in place using laravel eloquent.

Is there any way to do so or any best practice for it?

What I have in mind :

Orders::where('user_id', '!=', $user_id)
 ->where('odm_id', $odm_id)
 ->whereExpired(0)
 ->min('priority')
 ->update(['priority' => 1]);

FYI: Above approach is giving an error and is not working. The Error Message is :

Call to a member function update() on string

Author:Mohammad_Hosseini,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/51944101/laravel-eloquent-update-record-with-minimum-value
yy