if query returns nothing then laravel code example
Example 1: how to check if eloquent result is empty
Note:- Credit for this result goes to Alberto Peripolli. Copied from his Grepper.
if ($result->first()) { }
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }
Example 2: laravel check if query builder is empty
@if ($query === null)
{
<h4 style="text-transform: lowercase;">no results for: #{{ $query }}</h4>
}
@else
{
<h4 style="text-transform: lowercase;">results for: #{{ $query }}</h4>
}
@endif