在laravel的注册系统中有一个函数guard((
protected function guard(){
return Auth::guard();
}
现场
vendor/lavel/ui/auth-backend/RegisterUsers.php
并且寄存器的函数使用这个保护函数
public function register(Request $request){
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
if ($response = $this->registered($request, $user)) {
return $response;
}
return $request->wantsJson()
? new Response('', 201)
: redirect($this->redirectPath());
}
当我想为另一个警卫建立一个注册系统时,我只会覆盖警卫功能,然后像一样
protected function guard(){
return Auth::guard('admin');
}
所有这些都很好但是在电子邮件验证中,guard((函数不存在它使用$request->user()
而是像
public function resend(Request $request)
{
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson()
? new Response('', 204)
: redirect($this->redirectPath());
}
$request->user()->sendEmailVerificationNotification();
return $request->wantsJson()
? new Response('', 202)
: back()->with('resent', true);
}
那么,在这种情况下,如果我想覆盖防护怎么办我想把(重新发送(的整个功能都用掉,但我认为这不是最好的解决方案有人能告诉我怎么做吗
而不是覆盖guard的函数我只会用构造函数中的shouldUse()
函数就像那样auth()->shouldUse('admin');
然后当我使用request->user()
时,它会自动将其用作管理员保护