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:
-
Inside your Laravel project, go to
resources/views. -
Create a new file, for example
home.blade.php. -
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
Using a Controller:
-
Create controller (if not there):
-
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');
}
}
-
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:
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.phpextension -
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.
