Laravel Blade @unless Directive Example

By Hardik Savani November 5, 2023 Category : Laravel

In this quick example, let's see laravel blade @unless directive. i explained simply step by step laravel blade unless example. i explained simply step by step @unless laravel blade example. let’s discuss about laravel blade unless directive.

@unless directive is work reverse of if condition, i mean it's work with ! in the condition itself.

we will learn simple example of @unless directive and you can use in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10.

let's see bellow simple example:

Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

@unless ($admin)

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

@endunless

@if(!empty($admin))

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

@else

<p> admin variable is empty.</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()

{

$admin = 1;

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

}

}

Output:

admin variable is not empty.

admin variable is not empty.

I hope it can help you...

Tags :
Shares