What are Laravel Blade Views

In Laravel, a view is the part of the application that handles what users see the HTML and simple layouts. It is separate from logic (controllers, models). Using views helps you keep your code clean: logic stays in controllers or models, only frontend in view files.

Blade is Laravel’s templating engine. A Blade view uses the .blade.php extension. Blade provides friendly syntax, such as {{ $variable }} for echoing content, looping, conditions etc. It helps when you want dynamic data, not just static HTML.

All view files are by default stored in the resources/views folder. So when you create a Blade view, put it in that folder (or subfolder).

Creating Your First Blade File (.blade.php)

Let’s make your very first Blade view.

Steps:

  1. Inside your Laravel project, go to resources/views.

  2. Create a new file, for example home.blade.php.

  3. In that file, write simple HTML, for example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Hello World!</h1>
</body>
</html>

Now you have created a Blade view: home.blade.php.

Returning Views from Routes / Controllers

To show that view in browser, you need to return it from a route or controller.

Using a Route:

Open routes/web.php, then add

Route::get('/', function () {
    return view('home');
});
When you navigate to http://127.0.0.1:8000/ in Locallhost, Laravel will look for resources/views/home.blade.php and show it.
 
Laravel blade view home page

Using a Controller:

  1. Create controller (if not there):

     
    php artisan make:controller PageController
  2. In app/Http/Controllers/PageController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PageController extends Controller
{
    public function home()
    {
        return view('home');
    }
}
  1. Define route:

Route::get('/home', [PageController::class, 'home']);

This also returns the Blade view.

If you use subfolders inside resources/views, you refer by dot syntax. Example: resources/views/pages/about.blade.php is accessed by view('pages.about').

Passing Variables & Arrays to Views

Often, you want to send data from controller or route into view so Blade can show dynamic content.

Passing a single variable:

Route::get('/greet', function () { 
$name = 'Ahmad'; 
return view('greet', ['name' => $name]); 
});

Then in resources/views/greet.blade.php:

 
<!DOCTYPE html> 
<html> 
<head>
<title>Greet</title>
</head> 
<body> 
<h1>Hello, {{ $name }}</h1> 
</body> 
</html>

Passing multiple variables:

You can pass more than one:

return view('profile', [ 'name' => 'Sara', 'email' => 'sara@example.com' ]);

Inside profile.blade.php, use:

<p>Name: {{ $name }}</p> <p>Email: {{ $email }}</p>

Using compact() helper:

$name = 'Ali'; $age = 30; return view('user', compact('name', 'age'));

The compact('name','age') builds an array ['name' => $name, 'age' => $age].

Examples Table

Route / Controller Code View File What You See when Load
return view('home'); home.blade.php Static content from home view
return view('pages.about'); resources/views/pages/about.blade.php About page content
return view('greet', ['name' => 'Ahmad']); greet.blade.php “Hello, Ahmad”
return view('user', compact('name','age')); user.blade.php Shows name and age values

 


Summary

In this lesson you learned:

  • What Laravel views are, and why they matter

  • What a Blade view is, with .blade.php extension

  • How to create your first Blade view inside resources/views

  • How to return views from both routes and controllers

  • How to pass variables and arrays to view, plus using compact()

Next lesson will build on this: Blade syntax & directives (loops, conditions etc.), so you can do more dynamic pages.