Laravel Checking If a Record Exists

2019-01-08 03:32发布

I am new to Laravel. Please excuse the newbie question but how do I find if a record exists?

<?php

$user = User::where('email', '=', Input::get('email'));

What can I do here to see if $user has a record?

14条回答
我只想做你的唯一
2楼-- · 2019-01-08 04:19
$user = User::where('email', request('email')->first();
return (count($user) > 0 ? 'Email Exist' : 'Email Not Exist');
查看更多
走好不送
3楼-- · 2019-01-08 04:20
if (User::where('email', Input::get('email'))->exists()) {
    // exists
}
查看更多
登录 后发表回答