Create New ToDo Items

Welcome! In our previous lesson, you enhanced your ToDo application by enabling the retrieval of individual ToDo items using their ID. Now, it's time to take a step further by adding the functionality to create new ToDo items. This ability is a core feature in any dynamic application, allowing users to contribute and manage data effectively. By the end of this lesson, you'll have a user-friendly interface for adding new tasks to your ToDo list.

What You'll Learn

In this lesson, you will learn how to allow users to create new ToDo items in your Laravel application. You will achieve this by:

  1. Updating the view to include a form where users can enter new ToDo items.
  2. Modifying the TodoController to handle form submissions and validate user input.
  3. Enhancing the TodoService to save the new ToDo items in a persistent manner.

Let's start with the view, that is used to capture user input for creating new ToDo items.

This form will capture the user's input - a title and an optional description - and submit it to the ``/todos` endpoint. The @csrf directive generates a hidden input field with a CSRF token, which is required to protect your application from cross-site request forgery (CSRF) attacks.

You'll update your TodoController to look like this:

We have a new method, called store, that handles the form submission. Let's see how it works:

  1. The method receives a Request object, which contains the user's input - the title and description of the new ToDo item.
Why It Matters

The ability to create new items is crucial in designing interactive and useful applications. It empowers users to add tasks as they see fit, making the application dynamic and adaptable to their needs. Whether you're building a task manager, a shopping list, or any other app requiring user input, this functionality provides the building blocks for user engagement and data management.

Creating new items also teaches you how to handle form data, validate input, and update persistent storage — skills that are universally applicable across web development projects. Excited to add this new feature to your app? Let's move to the practice section and implement it together!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal