在Laravel

时间:2018-06-17 22:45:05

标签: laravel authentication laravel-5.4

我在Laravel中的应用程序在注册后出现以下错误: “BadMethodCallException 调用未定义的方法Illuminate \ Database \ Query \ Builder :: getAuthIdentifierName()“ 仅在执行身份验证后才会显示错误。如果我清除浏览器的缓存,则错误消失,应用程序正常工作。 我已经在StackOverflow和其他网站上看到了其他答案,但没有一个能解决我的问题。可能会发生什么?

这是我的User.php文件:

use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'cpf', 'name', 'lastname', 'email', 'password', 'auth', 'authy_id', 'api_token', 'block', 'blocked_at', 'session'
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

我的代码验证在这里:

public function auth($session, $gtag){
    $user = User::where('session', $session)->first();
    if(isset($user) && !empty($user)){
        Auth::login($user);

        //$time = decrypt($user->session);
        $user->session = NULL;
        $user->save();

        setcookie('_ga', $gtag, (time() + 605800), '/', 'bmydomain.com');
        setcookie('_gat_gtag_UA_115432851_1', '1', (time() + 605800), '/', 'mydomain.com');

        return redirect($this->redirectTo);
    }
    else{
        return redirect($this->redirectNotAuth);
    }
}

1 个答案:

答案 0 :(得分:1)

在Kernel.php文件上使用:

'auth' => \Illuminate\Auth\Middleware\Authenticate::class,

代替

'auth' => \App\Http\Middleware\Authenticate::class,