Laravel Blade Empty Directive Example

By Hardik Savani | March 3, 2021 | Category : Laravel


Hi,

If you need to see example of laravel blade empty directive. we will help you to give example of laravel blade check if variable is empty. i explained simply step by step check empty in laravel blade. This article goes in detailed on laravel @empty directive example.

we will learn simple examples of how to check variable is empty or not in laravel 6, laravel 7 and laravel 8.

let's see bellow simple example:

Blade File Code:

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

@empty($user)

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

@endempty

@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()

{

$user = '';

$admin = 1;

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

}

}

Output:

user variable is empty.

admin variable is not empty.

I hope it can help you...



Tags : Laravel


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: