Category : #laravel
Tags : #laravel, #laravel blade template
In this tutorial, I will show you how to write if else statement and multiple if else statements in the Laravel blade file. You know that blade is a template engine and we can not use normal PHP without using the @php
@endphp
blade directive. But we can do it in the blade file also.
Let's see the example code:
resources/views/welcome.blade.php
@if($user->name == 'John Doe')
{{ 'do something' }}
@endif
We can also if else ladder in blade file. See the code:
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif
Hope it can help you.