Skip to main content
This endpoint requires an active authenticated session. Unauthenticated requests are redirected to the login page.

Endpoint

PUT /tasks/{id}/complete

Description

Finds a task by its id and sets completed = 1, then returns the updated task object in the response.
Once a task is marked as completed, it is excluded from the GET /tasks/index response, which filters on completed = 0. The task will disappear from the active task list the next time fetchTasks is called.

Path parameters

id
integer
required
The unique identifier of the task to mark as completed.

Response

Returns a JSON object with a confirmation message and the updated task.

Response fields

message
string
A confirmation string. Value: "Task completed successfully."
task
object
The full task object after the update.

Example response

{
  "message": "Task completed successfully.",
  "task": {
    "id": 1,
    "user_id": 3,
    "title": "Review pull request",
    "description": "Check the open PR for the billing module.",
    "completed": 1,
    "created_at": "2026-03-18T10:00:00.000000Z",
    "updated_at": "2026-03-18T12:45:00.000000Z"
  }
}

Error response

If no task with the given id exists:
{
  "error": "Task not found."
}
HTTP status: 404

Controller code

// app/Http/Controllers/TaskController.php

// Actualizar tarea
public function update(Request $request, $id)
{
   // Buscar la tarea
    $task = Task::find($id);

    if (!$task) {
        return response()->json(['error' => 'Task not found.'], 404);
    }

    // Actualizar el estado 'completed' a 1
    $task->completed = 1;
    $task->save();

    return response()->json(['message' => 'Task completed successfully.', 'task' => $task], 200);
}

Frontend Axios call

// resources/js/store.js — completeTask action

completeTask({ commit }, taskId) {
    axios.put(`/tasks/${taskId}/complete`)
        .then(response => {
            commit('UPDATE_TASK', response.data.task); // Actualizar la tarea
        })
        .catch(error => {
            console.error("Error completing task:", error);
        });
}