尝试登录用户时,方法Illuminate \ Auth \ RequestGuard :: attempt不存在

问题描述

我的应用程序创建了从电子表格派生的用户。他们使用“个人信息”登录,然后为该帐户创建密码。起初有点像软登录,然后他们通过声明帐户来完成注册

一旦发生“软登录”并且帐户被“声明”,每次用户轻柔地登录时,我的中间件都会将他们重定向到密码页面,然后在该页面输入密码。

一旦他们这样做了,我需要确认这是正确的密码。到目前为止,我做到了:

public function auth(Request $request)
{
    $request->validate([
        'password' => 'required'
    ]);

    if(Auth::attempt([
        // Auth::user() works because they are "soft logged in"
        // However,middleware prevents all routes until they authenticate
        // Their password once the accounts claimed
        'id' => Auth::user()->getAuthIdentifier(),'password' => $request->input('password'),])) {
        DB::table('sessions')->where('user_id','=',Auth::user()->getAuthIdentifier())
                ->where('user_agent',$request->server('HTTP_USER_AGENT'))
                ->update([
                    'authenticated' => true
                ]);

        return redirect(route('dashboard'));
    }

    return Redirect::back()->withErrors(['Invalid password. Please try again.']);
}

我遇到的问题是attempt给了我这个错误

Method Illuminate\Auth\RequestGuard::attempt does not exist. 

我在Auth.PHP配置文件中检查了我的卫队:

'guards' => [
    'web' => [
        'driver' => 'session','provider' => 'users',],'api' => [
        'driver' => 'token','hash' => false,

并且driver设置为session,所以我现在不确定是什么引起了这个问题。任何帮助都会很棒。

解决方法

目前,我已经使用password_verify()

解决了此问题
        $hash = DB::table('users')->select('password')
                ->where('id','=',Auth::user()->getAuthIdentifier())
                ->get()
                ->all()[0]->password;

        if(password_verify($request->input('password'),$hash)) {
            DB::table('sessions')->where('user_id',Auth::user()->getAuthIdentifier())
                    ->where('user_agent',$request->server('HTTP_USER_AGENT'))
                    ->update([
                        'authenticated' => true
                    ]);

            return redirect(route('dashboard'));
        }