Laravel blades

Rendering a view in browser
Route::get('/', function () {
return view('welcome', ['name' => 'Samantha']);
});
Using variables in blades
Hello, {{ $name }}
Include php scripts
@php
$counter = 1;
@endphp
Example blade directives
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don t have any records!
@endif
@unless (Auth::check())
You are not signed in.
@endunless
@isset($records)
@endisset
@empty($records)
@endempty
@auth
@endauth
@guest
@endguest
@auth('admin')
@endauth
@guest('admin')
@endguest
@production
@endproduction
@env('staging')
@endenv
@env(['staging', 'production'])
@endenv
@switch($i)
@case(1)
First case...
@break
@case(2)
Second case...
@break
@default
Default case...
@endswitch
Loops
@for ($i = 0; $i < 10; $i++)
The current value is {{ $i }}
@endfor
@foreach ($users as $user)
<div>This is user {{ $user->id }}</div>
@endforeach
@forelse ($users as $user)
<li>{{ $user->name }}</li>
@empty
<div>No users</div>
@endforelse
@while (true)
<div>I am looping forever.</div>
@endwhile
loop variables avalable
@foreach ($users as $user)
@foreach ($user->posts as $post)
@if ($loop->parent->first)
This is the first iteration of the parent loop.
@endif
@endforeach
@endforeach
$loop->index/iteration/remaining/count/first/last/even/odd/depth/parent
Conditional Classes
@php
$isActive = false;
$hasError = true;
@endphp
<span @class([
'p-4',
'font-bold' => $isActive,
'text-gray-500' => ! $isActive,
'bg-red' => $hasError,
])></span>
<span class="p-4 text-gray-500 bg-red"></span>