Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if collection empty in view blade laravel?

If I dd($items); in the controller, the result like this :

enter image description here

In the view blade laravel I check if collection empty like this :

@if($items)
...
@endif

But it does not work

How can I solve this problem?

like image 410
moses toh Avatar asked Dec 08 '22 14:12

moses toh


1 Answers

You could use $items->isEmpty(); or $items->isNotEmpty();

Like so:

@if(!$items->isNotEmpty())
...
@endif

You can further read over here: https://laravel.com/docs/5.5/collections#method-isempty

like image 51
MyLibary Avatar answered Jan 13 '23 12:01

MyLibary