Eloquent ->first() if ->exists()

前端 未结 5 615
天涯浪人
天涯浪人 2020-12-23 09:08

I want to get the first row in table where condition matches:

User::where(\'mobile\', Input::get(\'mobile\'))->first()

It works well, bu

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 09:53

    (ps - I couldn't comment) I think your best bet is something like you've done, or similar to:

    $user = User::where('mobile', Input::get('mobile'));
    $user->exists() and $user = $user->first();
    

    Oh, also: count() instead if exists but this could be something used after get.

提交回复
热议问题