我正在尝试添加新用户,但是遇到错误消息,提示调用未定义的方法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();
}