Laravel: find out if variable is collection
You can try something like this if(is_a($images, ‘Illuminate\Database\Eloquent\Collection’)) { ….do whatever for a collection…. } else { ….do whatever for not a collection…. } Or if ($images instanceof \Illuminate\Database\Eloquent\Collection) { ….do whatever for a collection…. }