使用查询构建器登录

时间:2017-12-30 10:02:50

标签: laravel query-builder

如何使用此queryBuilder检查laravel中的用户是否存在? 问题是检查密码:

 $user = DB::table('users')
        ->where('email',$request->input('email'))
        ->where('password',bcrypt($request->input('password')))
        ->first();

2 个答案:

答案 0 :(得分:2)

使用auth()->attempt()

auth()->attempt(['email' => $request->email, 'password' => $request->password])

如果您只想检查密码,请使用Hash::check()

Hash::check($request->password, $passwordFromDb)

答案 1 :(得分:2)

收到电子邮件

$user = DB::table('users')
    ->where('email',$request->input('email'))
    ->first();

检查密码

use Illuminate\Support\Facades\Hash;
    if(Hash::check($user->password,Hash::make($request->input('password')))){   echo"Password current"; }else{ echo "Password Wrong";}