First of all, we make a condition.blade.php file in which we define our conditions. See the below image.

After that, we make a function named condition in the controller Defined a variable $name, and assigned a string Sushant into it. After that returned it to view(condition.blade.php file is in a test folder). See the below image for help.

After that, we configure our Route. See below how I configured,

@if and @else Condition

Condition written under if statement is executed when it’s True otherwise else executed. See the below Example:-

Sample Program

In the above program, if-statement is true so it gives output String is > 0. See the output below:-

Output

@elseif Condition

The else-if statement is written after the if and before the else statement and it executes when the if statement is false. See the below example:-

Sample Program

In the above program, if the condition is false so else if the condition checked whether it’s true or false if it’s true then it is executed otherwise else condition is executed. But in the above program else if the condition is true, so it’s executed and gives the output:- String is in between 5 and 10. See the output below.

Output

@isset Condition

@isset statement is used to check whether the variable we called is defined or not. If not defined then it’s not executed and prints next statement but doesn’t return an error. See the below example:-

Sample program

In the above program, Variable $string is not defined so @isset statement is not executed and the next statement prints. See the below output

@empty Condition

The @empty statement is used to check whether the called variable has value or not. If no value is assigned to the variable then statement executed otherwise not executed. See the below example:-

Sample Program

In the above program, Variable $name has no value, so when we check $name then it returns statement written under @empty condition.

Output

@unless Condition

It is used to check whether the array or variable we called has any value declared or not. If no value is assigned to the variable or array then statement executed otherwise not executed. See the below example:-

 

Sample Program

In the above program, there is no value assigned to the variable $name so it returns a Value that is empty. See the output below:-

Leave a Comment
No Comments found