Skip to content

Instantly share code, notes, and snippets.

@omurphy27
Created December 28, 2016 20:52
Show Gist options
  • Save omurphy27/5b0ac2d5d6cc02ff0dfa36b099ea3eac to your computer and use it in GitHub Desktop.
Save omurphy27/5b0ac2d5d6cc02ff0dfa36b099ea3eac to your computer and use it in GitHub Desktop.
Laravel - Determine if an Eloquent Collection from Get has results or is empty
<?php
$result = Model::where(...)->get();
if ($result->first()) { }
if (!$result->isEmpty()) { }
if ($result->count()) { }
if (count($result)) { }
// see here: http://stackoverflow.com/questions/20563166/eloquent-collection-counting-and-detect-empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment