Laravel检查用户是否存在

hat*_*apo -5 validation laravel

我正在使用Laravel 5.2.45

我正在尝试为我的应用程序创建新用户.在创建用户之前,我需要检查是否存在具有相同名称,姓氏和生日的用户.我怎么能在laravel中做到这一点?

Cap*_*ext 5

具有相同姓名,姓氏和生日的用户

$duplicate_user = \DB::table('users')
    ->where('name', 'LIKE', $new_name)
    ->where('surname', 'LIKE', $new_surname)
    ->where('birthday', '=', $new_birthday)
    ->first();

if($duplicate_user) {
    return response('This user already exists', 422);
}
Run Code Online (Sandbox Code Playgroud)