laravel eloquent check if 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: 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 3: check count in laravel

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

Tags:

Css Example