最佳答案
I want to get the first row in table where condition matches:
User::where('mobile', Input::get('mobile'))->first()
It works well, but if the condition doesn't match, it throws an Exception:
ErrorException
Trying to get property of non-object
Currently I resolve it like this:
if (User::where('mobile', Input::get('mobile'))->exists()) {
$user = User::where('mobile', Input::get('mobile'))->first()
}
Can I do this without running two queries?