Mahamudul Hasan Rubel
HomeBlogCoursesAboutProjectsSkillsExperiencePhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • Blog
  • Courses
  • About
  • Projects
  • Skills
  • Experience
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Lesson 39 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 25, 20263 min read

Task Manager: Adding Status and Priorities in Laravel

Enhance your Task Manager with status and priority fields. Learn how to evolve your database schema, update your Blade UI, and implement state toggling.

LaravelDatabaseUXCRUDMigrationsphpbackend

Previously in this course, we finished Task Manager: Completing CRUD Functionality in Laravel. Now, it’s time to move beyond basic text fields. A real-world Task Manager needs to track progress and urgency, so we’ll add status and priority columns to our database and expose them in our UI.

Evolving the Database Schema

When your application grows, your database needs to follow suit. We've already covered the basics of Understanding Database Migrations, so we’ll jump straight into creating a migration to modify our existing tasks table.

Run this command in your terminal:

Bash
php artisan make:migration add_status_and_priority_to_tasks_table --table=tasks

Open the generated file in database/migrations. We will add two columns: status (boolean, default false) and priority (integer, default 1).

PHP
public function up()
{
    Schema::table('tasks', function (Blueprint $table) {
        $table->boolean('is_completed')->default(false);
        $table->unsignedInteger('priority')->default(1);
    });
}

public function down()
{
    Schema::table('tasks', function (Blueprint $table) {
        $table->dropColumn(['is_completed', 'priority']);
    });
}

Run php artisan migrate to apply these changes. Ensure you update your Task model's $fillable property to allow mass assignment for these new fields, as we learned in Preventing Mass Assignment in Laravel.

Implementing Status Toggling

To improve the UX, we want to allow users to toggle a task's status directly from the list view without navigating to an edit screen. We’ll add a simple route and controller method to handle this.

In your routes/web.php:

PHP
Route::patch('/tasks/{task}/toggle', [TasksController::class, 'toggle'])->name('tasks.toggle');

In your TasksController, implement the toggle logic:

PHP
public function toggle(Task $task)
{
    $task->update([
        'is_completed' => !$task->is_completed
    ]);

    return back()->with('success', 'Task status updated!');
}

Updating the UI

Now, we update our Blade view. Since we have a master layout, we can inject a small form into our list view to trigger the patch request.

HTML
@foreach ($tasks as $task)
    style="color:#808080"><style="color:#4EC9B0">div class="task-item">
        style="color:#808080"><style="color:#4EC9B0">form action="{{ route('tasks.toggle', $task) }}" method="POST">
            @csrf
            @method('PATCH')
            style="color:#808080"><style="color:#4EC9B0">button type="submit">
                {{ $task->is_completed ? 'Undo' : 'Complete' }}
            style="color:#808080"></style="color:#4EC9B0">button>
        style="color:#808080"></style="color:#4EC9B0">form>
        style="color:#808080"><style="color:#4EC9B0">span>{{ $task->title }} (Priority: {{ $task->priority }})style="color:#808080"></style="color:#4EC9B0">span>
    style="color:#808080"></style="color:#4EC9B0">div>
@endforeach

Hands-on Exercise

  1. Add Validation: Update your FormRequest to ensure the priority field is an integer between 1 and 3.
  2. Dynamic Styling: In your Blade template, add a CSS class (e.g., line-through) to the task title if $task->is_completed is true.
  3. Sorting: Modify your index query in the TasksController to sort tasks by priority descending, then by created_at descending.

Common Pitfalls

  • Mass Assignment: Forgetting to update the $fillable array in the model will cause the new fields to remain unchanged even if the request is successful.
  • Migration Order: If you try to run logic on a column before the migration has finished, you'll encounter "Column not found" errors. Always run migrations before updating your code logic.
  • CSRF tokens: Since you are using a form to trigger the toggle, never forget the @csrf directive, or you will receive a 419 error.

Recap

We successfully evolved our Task Manager by adding database columns and providing a seamless toggle mechanism. By leveraging migrations and simple controller actions, we've made the application more functional for the end user. Database changes are a natural part of the development lifecycle, and mastering these incremental updates is key to building maintainable software.

Up next: We will learn about Introduction to Artisan Commands to automate repetitive tasks and gain deeper insights into our application.

Previous lessonUsing Flash Messages for User FeedbackNext lesson Introduction to Artisan Commands
Back to Blog

Similar Posts

LaravelJune 25, 20263 min read

Using Flash Messages for User Feedback in Laravel

Learn how to implement session flash messages in your Laravel Task Manager to provide immediate, professional feedback after users save or delete data.

Read more
LaravelJune 25, 20263 min read

Task Manager: Completing CRUD Functionality in Laravel

Finalize your Task Manager CRUD functionality by implementing secure edit and delete features. Learn how to maintain data integrity in your Laravel application.

Part of the course

Laravel Fundamentals: From Zero to Your First App

beginner · Lesson 39 of 52

  1. 1

    Setting Up the Local Development Environment

    4 min
  2. 2

    Installing Laravel and Exploring Directory Structure

    3 min
  3. 3

    Understanding the .env File and Configuration

    3 min
Read more
LaravelJune 25, 20263 min read

Deleting Records: A Laravel CRUD Guide

Master the final step of CRUD by learning to delete records safely in Laravel. We cover DELETE requests, route naming, and Eloquent deletion.

Read more
  • 4

    The Laravel Application Lifecycle

    4 min
  • 5

    Initializing the Task Manager Project

    3 min
  • 6

    Defining Basic Web Routes

    4 min
  • 7

    Using Route Parameters

    3 min
  • 8

    Creating Your First Controller

    3 min
  • 9

    Returning Responses and Redirects

    3 min
  • 10

    Task Manager: Implementing the Task List Route

    3 min
  • 11

    Introduction to Blade Templating

    3 min
  • 12

    Using Blade Layouts and Sections

    3 min
  • 13

    Implementing Blade Partials

    4 min
  • 14

    Mastering Blade Directives for Loops and Conditionals

    3 min
  • 15

    Task Manager: Building the User Interface

    3 min
  • 16

    Understanding Database Migrations

    3 min
  • 17

    Working with Eloquent Models

    3 min
  • 18

    Performing Basic CRUD Operations

    3 min
  • 19

    Seeding the Database

    3 min
  • 20

    Task Manager: Displaying Real Database Records

    3 min
  • 21

    Capturing User Input from Forms

    4 min
  • 22

    Introduction to Laravel Validation

    3 min
  • 23

    Customizing Validation Error Messages

    3 min
  • 24

    Using Form Requests for Validation

    3 min
  • 25

    Introduction to Authentication

    4 min
  • 26

    Protecting Routes with Middleware

    3 min
  • 27

    Understanding CSRF Protection

    3 min
  • 28

    Preventing Mass Assignment

    3 min
  • 29

    Task Manager: Securing the Application

    3 min
  • 30

    Introduction to Route Model Binding

    3 min
  • 31

    Updating Existing Records

    3 min
  • 32

    Deleting Records

    3 min
  • 33

    Using Named Routes

    3 min
  • 34

    Task Manager: Completing CRUD Functionality

    3 min
  • 35

    Introduction to Database Relationships

    3 min
  • 36

    Querying Related Data

    4 min
  • 37

    Handling File Uploads

    3 min
  • 38

    Using Flash Messages for User Feedback

    3 min
  • 39

    Task Manager: Adding Status and Priorities

    3 min
  • 40

    Introduction to Artisan Commands

    3 min
  • 41

    Debugging with Laravel Tinker

    3 min
  • 42

    Understanding Service Providers

    4 min
  • 43

    Using View Composers

    3 min
  • 44

    Task Manager: Refactoring for Clean Code

    3 min
  • 45

    Introduction to Testing

    Coming soon
  • 46

    Testing Forms and Validation

    Coming soon
  • 47

    Using Database Transactions

    Coming soon
  • 48

    Handling Global Exceptions

    Coming soon
  • 49

    Preparing for Production

    Coming soon
  • 50

    Environment Security Best Practices

    Coming soon
  • 51

    Managing Assets in Production

    Coming soon
  • 52

    Task Manager: Deployment Preparation

    Coming soon
  • View full course