Laravel Check if Variable Exist in Blade (View) Directive
In this short article, I’m going to share some ways to check if variable exist in the blade file. Let’s see:
Table of Contents
Laravel @isset Directive
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
@isset($variable)
{{ $variable }}
@endisset
</body>
</html>
Laravel @empty Directive
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
@empty($variable)
{{ $variable }}
@endempty
</body>
</html>
Laravel if isset() Method
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
@if(isset($variable))
{{ $variable }}
@endif
</body>
</html>
Laravel Ternary Operator
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<!-- way 1 -->
{{ $varible ?? 'default' }}
<!-- way 2 -->
{{ $variable or "default" }}
</body>
</html>
That’s all. Thank you.

Md Obydullah
https://shouts.dev/obydul
Comments
No comments yet…