authorize('update', $channel); $data = request()->validate([ 'ids' => 'array|min:1', 'ids.*' => 'int', 'modelType' => 'required|string', ]); $queryPart = ''; foreach ($data['ids'] as $order => $id) { $queryPart .= " when channelable_id=$id then $order"; } DB::table('channelables') ->where('channel_id', $channel->id) ->whereIn('channelable_id', $data['ids']) ->where('channelable_type', $data['modelType']) ->update(['order' => DB::raw("(case $queryPart end)")]); return $this->success(); } }