> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/estebansalas94/Prueba-Soporte/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete a task

> Permanently deletes a task by ID. This action cannot be undone.

<Note>
  This endpoint requires an active authenticated session. Unauthenticated requests are redirected to the login page.
</Note>

## Endpoint

```
DELETE /tasks/{id}
```

## Description

Permanently removes a task record from the database using `findOrFail`. If the task does not exist, Laravel returns a `404` response automatically.

<Warning>
  Deletion is permanent and cannot be undone. There is no soft-delete or archive mechanism. Once deleted, the task record is gone from the database.
</Warning>

## Path parameters

<ParamField path="id" type="integer" required>
  The unique identifier of the task to delete.
</ParamField>

## Response

Returns a JSON object confirming deletion.

### Response fields

<ResponseField name="message" type="string">
  A confirmation string. Value: `"Task deleted successfully"`
</ResponseField>

## Example response

```json theme={null}
{
  "message": "Task deleted successfully"
}
```

HTTP status: `200`

## Error response

If no task with the given `id` exists, Laravel's `findOrFail` throws a `ModelNotFoundException` and returns:

```json theme={null}
{
  "message": "No query results for model [App\\Models\\Task] {id}."
}
```

HTTP status: `404`

## Controller code

```php theme={null}
// app/Http/Controllers/TaskController.php

// Eliminar tarea
public function destroy($id)
{
    $task = Task::findOrFail($id);
    $task->delete();

    return response()->json(['message' => 'Task deleted successfully'], 200);
}
```

## Frontend Axios call

```javascript theme={null}
// resources/js/store.js — deleteTask action

deleteTask({ commit }, taskId) {
    axios.delete(`/tasks/${taskId}`)
        .then(() => {
            commit('DELETE_TASK', taskId);
        })
        .catch(error => {
            console.error("Error deleting task:", error);
        });
},
```
