Views are stored in the resources/views/ directory and have the
.blade.php extension.
File: resources/views/home.blade.php
<html>
<head>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
Route::view('/home','home')
return view('home', ['name' => $name]);
In the Blade file:
<div>{{$name}}</div>
| Directive | Description |
|---|---|
| {{ $variable }} | Outputs a variable |
| @if( condition ) | Conditional statement |
|
@foreach($items as $item) <div>{{$item->id}}</div> @endforeach |
Loop through items |
| @include('view') | Includes another view |
| @extends('layout') | Uses a main layout file |
| @section('content') | Defines a content section |
| @isset('content') | Checks if a variable is set |
| @empty('content') | Checks if a variable is empty |
layouts/app.blade.php
<html>
<head>
</head>
<body>
<h1>This is the same on every page that extends the layout</h1>
@section('content')
@show
</body>
</html>
home.blade.php
@extends('layout')
@section('content')
This is different on every page
@endsection