Need to check if an object is empty in laravel
If it is a Eloquent Collection as it appears to be from your example you can use the isEmpty collection helper function;
@if(!$contacts->isEmpty())
//display contacts
@else
You dont have contacts
@endif
Collections Documentation
There are few ways:
if (!empty($contacts))
if (!contacts->isEmpty())
if (count($contacts) > 0)
if ($contacts->count() > 0)
Your Eloquent query returns an array of result, so you can use count
.
@if(count($contacts) > 0)
//Display contacts
@else
//No contacts
@endif