Skip to main content
Tasks move through a simple lifecycle: they are created with a title, description, and an assigned user, they appear in the active task list, and they are removed from the list when completed or deleted. All task operations go through a Vuex store that communicates with the Laravel backend over HTTP.

Task lifecycle

1

Create a task

The user fills in the task form at the bottom of the task list — providing a title, description, and the email address of the user to assign the task to — then clicks Add Task.The addTask method in TaskList.vue validates that all three fields are present, then dispatches the addTask action to the Vuex store:
On success, the form fields are cleared and the new task appears in the list.
2

Task appears in the active list

The Vuex store commits the ADD_TASK mutation, which appends the new task to the tasks array in state. The v-for loop in the template renders it immediately:
The task list only shows incomplete tasks. The backend index action filters by completed = 0, so any task marked as complete is excluded from the next fetch and disappears from the UI after the store is updated.
3

Complete a task

Clicking Complete calls completeTask(task.id) on the component, which dispatches to the store:
The store sends a PUT request to /tasks/{id}/complete and commits the updated task via UPDATE_TASK:
The UPDATE_TASK mutation replaces the task in the array in-place:
On the backend, the controller sets completed = 1 and saves:
4

Task is removed from the list

Because TaskController@index only returns tasks where completed = 0, the completed task will not appear the next time fetchTasks is called. The UPDATE_TASK mutation updates the local copy in state (including the new completed value), so the reactive list reflects the change without an extra round-trip.
5

Delete a task

Clicking Delete calls deleteTask(task.id), which dispatches to the store:
The store sends a DELETE request to /tasks/{id} and commits DELETE_TASK to remove the task from state:
The DELETE_TASK mutation filters the task out of the array immediately:
The backend controller uses findOrFail and permanently removes the record:

Fetching tasks on load

When TaskList.vue mounts, it immediately calls fetchTasks() to populate the store:
The store action hits GET /tasks/index and commits the response via SET_TASKS:
The backend returns only incomplete tasks:

Vuex store state shape

The store holds a single tasks array:
All four mutations (ADD_TASK, UPDATE_TASK, SET_TASKS, DELETE_TASK) operate on this array. A tasks getter is also exposed for convenience:
The component accesses the state directly via mapState: