In this tutorial i will show you to use if else, if and else if in Laravel blade. Laravel use blade engine to render the template and blade have rich features to use conditional statements in file. So here i will show you to use @if, @elseif and @else in blade file.
How to use @if condition in blade ?
In this section we will cover @if and @endif conditional statement with example.
Syntax
@if (condition)
// code here for the condition
@endif
Example
$a=5;
@if ($a>5)
<p>a is greater then 5</p>
@endif
How to use @if and @elseif condition in blade ?
In this section we will cover @if, @elseif and @endif conditional statement with example.
Syntax
@if (condition)
// code here for the condition
@elseif(secondconditon)
// code for second condition
@endif
Example
$a=5;
@if ($a>5)
<p>a is greater then 5</p>
@elseif ($a==5)
<p>a is 5</p>
@endif
How to use @if and @else condition in blade ?
In this section we will cover @if, @else and @endif conditional statement with example.
Syntax
@if (condition)
// code here for the condition
@else
// code for else condition
@endif
Example
$a=5;
@if ($a>5)
<p>a is greater then 5</p>
@else
<p>a is 5</p>
@endif
How to use @if, @else and @elseif condition in blade ?
In this section we will cover @if, @else, @elseif and @endif conditional statement with example.
Syntax
@if (condition)
// code here for the condition
@elseif(secondconditon)
// code for second condition
@else
//code for else
@endif
Example
$a=5;
@if ($a>5)
<p>a is greater then 5</p>
@elseif ($a==5)
<p>a is 5</p>
@else
<p>a is less then 5</p>
@endif