How to check if Laravel Foreach is Empty?
In this tutorial, we will learn How to check that Laravel Foreach is Empty?. If you have a question about the Laravel blade for each if not empty, then I give you a simple example. in this post, you will learn the Laravel blade for each empty and you can see the Laravel for each empty. We can do it basically four ways to check the Laravel array empty in the blade. so you can see below all examples step by step and you can use your client’s requirements.
How to check if foreach is empty in the Laravel application.
@forelse @empty
Controller Code
public function index() {
$users = User::get();
return view('users.index',compact('user'));
}
Blade Code
<div class="header">
<h1>How to check Laravel Foreach is Empty? - devnote.in</h1>
</div>
<div class="body">
@forelse($users as $value)
<p>user</p>
@empty
<p>No user</p>
@endforelse
</div>
@empty
Controller Code
public function index() {
$users = [];
return view('users.index',compact('user'));
}
Blade Code
<div class="header">
<h1>How to check Laravel Foreach is Empty? - devnote.in</h1>
</div>
<div class="body">
@empty($users)
<p>user</p>
@else
<p>No user</p>
@endforelse
</div>
@if empty()
Controller Code
public function index() {
$users = [];
return view('users.index',compact('user'));
}
Blade Code
<div class="header">
<h1>How to check Laravel Foreach is Empty? - devnote.in</h1>
</div>
<div class="body">
@if(empty($users))
<p>user</p>
@else
<p>No user</p>
@endforelse
</div>
@if count()
Controller Code
public function index() {
$users = User::get();
return view('users.index',compact('user'));
}
Blade Code
<div class="header">
<h1>How to check Laravel Foreach is Empty? - devnote.in</h1>
</div>
<div class="body">
@if($users->count() > 0)
<p>user</p>
@empty
<p>No user</p>
@endforelse
</div>