Search code examples
phplaravellaravel-5laravel-5.3laravel-collection

How to check if collection contains a value in Laravel


I am unable to check whether following collection contains data or not

$users = \App\Tempuser::where('mobile','=',$request->mobile)->get();

if(isset($users))
  return "ok";
else
  return "failed";

but if there is nothing in $users still i am not getting else part.


Solution

  • Use something like if ($users->count()) or if (count($users)).