laravel check if query returns empty code example

Example 1: laravel check if laravel query is empty

if ($result->first()) { } 
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }

Example 2: check count in laravel

$wordlist = Wordlist::where('id', '<=', $correctedComparisons)->get();
$wordCount = $wordlist->count();

Example 3: 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

Tags:

Css Example