用户数据存储在数据库中,但用户未定向到电子邮件确认页面

时间:2018-12-21 21:19:10

标签: php laravel-5.7

我正在尝试添加新用户,但是遇到错误消息,提示调用未定义的方法App\User::validate()。我不确定自己在做什么错。如果有人可以教我。

RedirectIfAuthenticated.php:

class RedirectIfAuthenticated
{
    public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/home');
        }

        return $next($request); /* I am having the problem here */
    }
}

User.php:

protected $fillable = [
    'name', 'email', 'password',
];

protected $hidden = [
    'password', 'remember_token',
];

public function roles()
{
    return $this->belongsToMany(Role::class);
}

public function checkRoles($roles)
{
    if ( ! is_array($roles)) {
        $roles = [$roles];
    }

    if ( ! $this->hasAnyRole($roles)) {
        auth()->logout();
        abort(404);
    }
}

public function hasAnyRole($roles): bool
{
    return (bool) $this->roles()->whereIn('name', $roles)->first();
}

public function hasRole($role): bool
{
    return (bool) $this->roles()->where('name', $role)->first();
}

0 个答案:

没有答案