📜  检查 laravel first null - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:33.203000             🧑  作者: Mango

代码示例1
$user = User::where('mobile', Input::get('mobile'))->first(); // model or null
if (!$user) {
   // Do stuff if it doesn't exist.
}
Other techniques (not recommended, unnecessary overhead):

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

if (!$user->isEmpty()){
    $firstUser = $user->first()
}