Laravel Blade If Condition Example

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

18352

07-01-2021


Hi Guys,

Today, I will explain you how to use laravel blade file in if condition. We will show example of laravel blade if condition. you can easy to use blade if else laravel.You may construct if statements using the @if, @elseif, @else, and @endif directives.

Here i give you full example of blade if condition in laravel.

Example: if...endif Condition


In this example, I will use if condition in blade file.

Syntax

@if (condition)

// Statements inside body of if

@endif

Example

@if (count($type) === 1)

I have one record!

@endif

Example: if..else..endif condition

Now this example, I will use if else condition in blade file.

Syntax

@if (condition)

// Statements inside body of if

@else

//Statements inside body of else

@endif

Example

@if (count($type) === 1)

I have one record!

@else

I don't have any records!

@endif

Example: if..elseif..else..endif Condition

Now this example, I will use if elseif else condition in blade file.

Syntax

@if (condition)

// Statements inside body of if

@elseif (condition)

// Statements inside body of else if

@else

//Statements inside body of else

@endif

Example

@if (count($type) === 1)

I have one record!

@elseif (count($type) > 1)

I have multiple records!

@else

I don't have any records!

@endif

It will help you....