【发布时间】:2020-07-19 10:21:13
【问题描述】:
在laravel的注册系统中有一个函数guard()
protected function guard(){
return Auth::guard();
}
在位置
vendor/laravel/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);
}
那么,如果我想在这种情况下覆盖守卫怎么办 我想覆盖(重新发送)的整个功能,但我认为这不是最好的解决方案 谁能告诉我该怎么做
【问题讨论】:
标签: php laravel authentication