Home > Net >  How to check laravel collection is empty in blade file?
How to check laravel collection is empty in blade file?

Time:05-19

I have added the condition like this @if(!empty($param)) but not working.

CodePudding user response:

assuming $param is a collection here, you can use isEmpty() or isNotEmpty() method like this:

@if($param->isNotEmpty())

Or

@unless($param->isEmpty())

CodePudding user response:

You can use isempty method of laravel collection to check whether a collection is empty or not. For more detail you can check it in their document.

Laravel Collection: isempty Method

CodePudding user response:

You can use the count() method and do something like this :

@if($collection->count()) 

More details here.

CodePudding user response:

This also works:

@if(count($param) > 0)
  • Related