Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Conditional (@if, @else, @elseif, @isset, @empty, and @unless) Statements in Laravel.

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 and 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 wrote 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 if and before else statement and it executes when if statement is false. See the below example:-

Sample Program

In the above program, if condition is false so elseif condition checked whether it’s true or false, if it’s true then it executed otherwise else condition executed. But in the above program elseif 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 Value is empty. See the output below:-

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

What is Laravel and use cases of Laravel?

What is Laravel? Laravel is an open-source, free PHP web framework designed for the development of web applications following the model-view-controller (MVC) architectural pattern. It was generated…

Read More

Complete guide of Laravel certification courses, tutorials & training

What is Laravel Laravel is a reliable and simple to use open-source PHP framework. It adheres to the model-view-controller pattern of design. Laravel makes use of pre-existing…

Read More

Top 100 laravel interview questions and answers

1) What is Laravel? Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural pattern….

Read More

[SOLVED] Laravel : Supervisor FATAL/BACKOFF Exited too quickly (process log may have details)

Problem I’m trying to use Laravel queues with a supervisor but the service is not working properly. When I try to check status:$ sudo supervisorctl status$ laravel-worker:laravel-worker_00:…

Read More

How to Login with Token in Laravel PHP Framework?

How to Login with Token in Laravel PHP Framework? Step 1. Create a new Project, so write down the following command on Git Bash: Step 2. Move…

Read More

Directory Structure Of Laravel Application

devopsschool – This is Project Folder app – The app directory contains the core code of your application. bootstrap – The bootstrap directory contains the app.php file…

Read More