/** * Toggles a task active or inactive. * @param int $id * * @return int */ public function toggle($id) { $task = Models\Task::findOrFail($id); try { $task->active = $task->active === 1 ? 0 : 1; $task->queued = 0; $task->save(); return $task->active; } catch (\Exception $ex) { throw $ex; } }
public function toggleTask(Request $request, $uuid, $id) { $server = Models\Server::getByUUID($uuid); $this->authorize('toggle-task', $server); $task = Models\Task::findOrFail($id); if (!$task || $server->id !== $task->server) { return response()->json(['error' => 'No task by that ID was found associated with this server.'], 404); } try { $repo = new Repositories\TaskRepository(); $resp = $repo->toggle($id); return response()->json(['status' => $resp]); } catch (\Exception $ex) { Log::error($ex); return response()->json(['error' => 'A server error occured while attempting to toggle this task.'], 503); } }