company_id) ->first(); $new_status = $ts ? $ts->id : null; Task::where('status_id', $task_status->id) ->where('company_id', $task_status->company_id) ->update(['status_id' => $new_status]); parent::delete($task_status); return $task_status; } public function archive($task_status) { $task_status = TaskStatus::where('id', $task_status->id) ->where('company_id', $task_status->company_id) ->first(); $new_status = $task_status ? $task_status->id : null; Task::where('status_id', $task_status->id) ->where('company_id', $task_status->company_id) ->update(['status_id' => $new_status]); parent::archive($task_status); return $task_status; } public function reorder(TaskStatus $task_status) { nlog("i am dirty"); nlog(TaskStatus::query() ->where('company_id', $task_status->company_id) ->orderByRaw('ISNULL(status_order), status_order ASC') ->orderBy('status_order', 'DESC')->pluck('name')); TaskStatus::query() ->where('company_id', $task_status->company_id) ->orderByRaw('ISNULL(status_order), status_order ASC') ->orderBy('status_order', 'DESC') ->cursor() ->each(function ($task_status, $index) { nlog($index." ".$task_status->name); $task_status->update(['status_order' => $index+1]); }); } }