- Hello, Visitor
- Monday, February 17, 2025
Search Result
Building a Task List with Priority Levels in Laravel
Posted by NzCoding - 18 October 2024

Introduction
In this tutorial, we’ll create a task list application using Laravel, where each task can be assigned a priority level. This feature is helpful for users to organize tasks based on urgency or importance. We'll explore how to set up the backend, define priority levels, and render tasks with color-coded priorities.
Step 1: Set Up Laravel Project
Create a new Laravel project and set up a database.
composer create-project laravel/laravel task-list cd task-list php artisan migrate
Step 2: Create the Task Model and Migration
Generate a model and migration for the Task
.
php artisan make:model Task -m
In the migration file, define fields for the task title, description, and priority.
Schema::create('tasks', function (Blueprint $table) { $table->id(); $table->string('title'); $table->text('description')->nullable(); $table->enum('priority', ['low', 'medium', 'high']); $table->timestamps(); });
Run the migration.
php artisan migrate
Step 3: Implement Task Management Logic
In TaskController.php
, define methods for creating, editing, and deleting tasks. Include logic to sort tasks by priority.
public function store(Request $request) { $validated = $request->validate([ 'title' => 'required|max:255', 'description' => 'nullable', 'priority' => 'required|in:low,medium,high', ]); Task::create($validated); return redirect()->route('tasks.index'); }
Step 4: Create Views with Priority Labels
In resources/views
, create a Blade template to list tasks with priority labels. Use Bootstrap classes for color-coding.
@foreach($tasks as $task) <div class="task-item {{ $task->priority }}"> <h5>{{ $task->title }}</h5> <p>{{ $task->description }}</p> <span class="badge bg-{{ $task->priority }}">{{ ucfirst($task->priority) }}</span> </div> @endforeach
Step 5: Test the Application
Run the server and navigate to the task list page to test adding and viewing tasks with priority levels.
php artisan serve
Conclusion
This simple application lets users manage tasks with priority levels, offering an organized way to handle tasks based on urgency. You can extend this application by adding filters or notifications for high-priority tasks.
Related posts
Simple User Registration with Laravel Fortify
Building a Simple To-Do List with Laravel Livewire 3: Add & Delete Tasks in Real-Time
Laravel Livewire 3: Building Dynamic Web Apps Made Easy
Live Form Validation with Laravel Livewire
Auto Generate Slug with Laravel Livewire
Laravel Add Data to Database with Database Seeder
Laravel Livewire Crud - Part 04 (Delete Data)
Laravel Livewire Crud - Part 03 (Edit Data)
Laravel Livewire Crud - Part 02 (Get Data from Database)
Laravel Livewire Crud - Part 01 (Add Data to Database)
Laravel Livewire Installation & Layout Setup
How to Clear Cache In Laravel 8
Laravel Livewire Image Upload with Preview
Laravel Livewire CRUD with Bootstrap Modal
Popular Posts
Featured Post
Categories
- Html Css 7
- More 3
- Card Design 2
- Spinner 2
- GitHub 2
- Laravel 16
- Livewire 12
- Javascript 1
- Form Design 1
- SEO 1
- Php 0
Leave a Reply