Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogCoursesPhotosContact
Mahamudul Hasan Rubel

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

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Courses
  • 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 15 of the Laravel Fundamentals: From Zero to Your First App course
LaravelJune 25, 20263 min read

Task Manager: Building the User Interface with Blade

Learn how to build a professional UI for your Task Manager using Blade layouts and dynamic loops. We'll connect your controller logic to a clean, DRY view.

LaravelBladeUIPHPBeginnerbackend

Previously in this course, we covered Implementing Blade Partials: A Guide to DRY Laravel Views and Mastering Blade Directives for Loops and Conditionals. In this lesson, we’re going to stop working with isolated snippets and bring everything together to build the actual frontend for our Task Manager.

By the end of this session, you’ll have a professional, reusable layout structure and a dynamic task list that renders data directly from your controller.

The Power of a Master Layout

When building a web application, you rarely want to rewrite your <head>, navigation, or footer tags for every single page. That’s a recipe for maintenance nightmares. Instead, we use a master layout—a "skeleton" that defines the structure of your site, into which individual page content is "injected."

Think of your master layout as a template that holds the constant parts of your application, while yield directives act as placeholders for the unique content of each specific route.

Step 1: Creating the Master Layout

Create a new file at resources/views/layouts/app.blade.php. This will be our base structure.

HTML
<!DOCTYPE html>
style="color:#808080"><style="color:#4EC9B0">html lang="en">
style="color:#808080"><style="color:#4EC9B0">head>
    style="color:#808080"><style="color:#4EC9B0">meta charset="UTF-8">
    style="color:#808080"><style="color:#4EC9B0">title>Task Managerstyle="color:#808080"></style="color:#4EC9B0">title>
style="color:#808080"></style="color:#4EC9B0">head>
style="color:#808080"><style="color:#4EC9B0">body>
    style="color:#808080"><style="color:#4EC9B0">nav>
        style="color:#808080"><style="color:#4EC9B0">h1>Task Managerstyle="color:#808080"></style="color:#4EC9B0">h1>
    style="color:#808080"></style="color:#4EC9B0">nav>

    style="color:#808080"><style="color:#4EC9B0">main>
        @yield('content')
    style="color:#808080"></style="color:#4EC9B0">main>

    style="color:#808080"><style="color:#4EC9B0">footer>
        style="color:#808080"><style="color:#4EC9B0">p>&copy; {{ date('Y') }} Task Manager Appstyle="color:#808080"></style="color:#4EC9B0">p>
    style="color:#808080"></style="color:#4EC9B0">footer>
style="color:#808080"></style="color:#4EC9B0">body>
style="color:#808080"></style="color:#4EC9B0">html>

Building the Task List View

Now that we have a structure, we need to display our tasks. In a real-world app, you'd fetch these from a database (which we’ll cover in upcoming lessons), but for now, we will pass a hardcoded array from our controller to our view to practice the rendering logic.

First, ensure your TasksController is passing data to the view. If you followed Task Manager: Implementing the Task List Route, your controller should look like this:

PHP
public function index()
{
    $tasks = [
        ['id' => 1, 'title' => 'Learn Laravel'],
        ['id' => 2, 'title' => 'Build a Task Manager'],
        ['id' => 3, 'title' => 'Deploy to production'],
    ];

    return view('tasks.index', compact('tasks'));
}

Step 2: Implementing Dynamic Loops

Create resources/views/tasks/index.blade.php. We will use the @extends directive to pull in our layout and @section to fill the content.

BLADE
@extends('layouts.app')

@section('content')
    <h2>Your Tasks</h2>

    <ul>
        @forelse ($tasks as $task)
            <li>{{ $task['title'] }}</li>
        @empty
            <li>No tasks found. Get to work!</li>
        @endforelse
    </ul>
@endsection

Using @forelse is a best practice here. It handles the empty state automatically, ensuring the user isn't staring at a blank screen if the task list is empty.

Hands-on Exercise

  1. Refactor your layout: Add a CSS link to your layouts/app.blade.php (you can use a simple CDN link for Tailwind CSS to make it look professional instantly).
  2. Add a status: Update your hardcoded $tasks array in the TasksController to include a completed boolean.
  3. Use conditionals: In your index.blade.php, use an @if directive inside your loop to strike through the task title if completed is true.

Common Pitfalls

  • Forgetting @endsection: If your layout isn't rendering, check that you closed your section with @endsection. Blade is strict about these tags.
  • Case Sensitivity: Blade filenames and folder structures are case-sensitive on Linux-based servers (like those used in production). Always use lowercase for directory and file names to avoid "View not found" errors when you eventually deploy.
  • Nesting Issues: Avoid putting your @extends directive inside a @section. The @extends must be at the very top of the file to tell Laravel which layout to wrap the content in.

Recap

We've moved from simple routes to a structured UI architecture. By using a master layout, we ensure our Task Manager remains DRY. By leveraging Blade directives like @forelse and @extends, we’ve created a clean, maintainable view layer that is ready to handle real database records.

Up next: We will dive into the database layer by exploring Database Migrations to store our tasks permanently.

Previous lessonMastering Blade Directives for Loops and ConditionalsNext lesson Understanding Database Migrations
Back to Blog

Similar Posts

LaravelJune 25, 20263 min read

Customizing Validation Error Messages for Better Laravel UX

Learn to customize Laravel validation error messages to provide clear, helpful feedback to your users. Master field-specific errors and language files.

Read more
LaravelJune 25, 20263 min read

Mastering Blade Directives for Loops and Conditionals

Learn how to use Blade directives like @if, @foreach, and @forelse to control your view logic and render dynamic lists in your Laravel applications efficiently.

Part of the course

Laravel Fundamentals: From Zero to Your First App

beginner · Lesson 15 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, 20264 min read

Implementing Blade Partials: A Guide to DRY Laravel Views

Stop repeating yourself in Blade templates. Learn how to implement Blade partials to extract common UI elements and keep your Laravel views maintainable.

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

    Coming soon
  • 27

    Understanding CSRF Protection

    Coming soon
  • 28

    Preventing Mass Assignment

    Coming soon
  • 29

    Task Manager: Securing the Application

    Coming soon
  • 30

    Introduction to Route Model Binding

    Coming soon
  • 31

    Updating Existing Records

    Coming soon
  • 32

    Deleting Records

    Coming soon
  • 33

    Using Named Routes

    Coming soon
  • 34

    Task Manager: Completing CRUD Functionality

    Coming soon
  • 35

    Introduction to Database Relationships

    Coming soon
  • 36

    Querying Related Data

    Coming soon
  • 37

    Handling File Uploads

    Coming soon
  • 38

    Using Flash Messages for User Feedback

    Coming soon
  • 39

    Task Manager: Adding Status and Priorities

    Coming soon
  • 40

    Introduction to Artisan Commands

    Coming soon
  • 41

    Debugging with Laravel Tinker

    Coming soon
  • 42

    Understanding Service Providers

    Coming soon
  • 43

    Using View Composers

    Coming soon
  • 44

    Task Manager: Refactoring for Clean Code

    Coming soon
  • 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