How to check if the result is empty for eloquent collection in Laravel?

A lot of times when coding we might encounter a problem where we have to check if the result we are getting has some data or not. But when we are working with eloquent results, even if it is empty, the function ’empty()’ holds false as well as ‘if($result)’ always holds true.

So to find out whether the eloquent collection is empty or not we have different ways

  • We count the number of data and check.
if($result->count()) {
    //record is exist true...
if(count($result)) {
    // record is exist true...
         // $result is not empty
        // $result is empty

There is also


These are the different ways you can check if the eloquent result is empty or not. Hope this helps you.

Leave a Comment

Your email address will not be published. Required fields are marked *