ItSolutionStuff.com

Laravel Blade Isset Else Example

By Hardik Savani • April 16, 2024
Laravel

Today, i will let you know example of laravel blade isset example. Here you will learn laravel blade isset directive. We will look at example of laravel blade @isset. step by step explain how to check variable is set or not in laravel. you will do the following things for how to check variable defined or not in laravel.

if you need to check variable set or not with if condition in laravel blade then i will give bellow example. you can also use in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

let's see bellow simple example:

Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

@isset($user)

<p> user variable is define.</p>

@endisset

@isset($status)

<p> status variable define.</p>

@endisset

@if(isset($admin))

<p> admin variable is define.</p>

@else

<p> admin variable is not define.</p>

@endif

</body>

</html>

Controller File Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AjaxController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function index()

{

$status = 1;

$admin = 1;

return view('ajaxRequest', compact('status', 'admin'));

}

}

Output:

status variable define.

admin variable is define.

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Blade Switch Case Statement Example

Read Now →

Laravel Blade If Multiple Conditions Example

Read Now →

Laravel Blade If Condition Example

Read Now →

Laravel nl2br Blade Directive Example

Read Now →

How to Create Custom Blade Directive in Laravel?

Read Now →

Laravel Blade Check If Variable is Set or Not Example

Read Now →

How to Write PHP Code in Laravel Blade?

Read Now →

Laravel - How to Check If Array is Empty in Blade?

Read Now →

How to use Inject View in Laravel?

Read Now →

Laravel Ajax Render View With Data Example

Read Now →

Laravel Blade Check if View Exists or Not Example

Read Now →