php - 电子邮件验证的多重身份验证 | 拉拉维尔
问题描述
在 laravel 的注册系统中有一个函数 guard()
protected function guard(){
return Auth::guard();
}
在位置
供应商/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);
}
那么,如果我想在这种情况下覆盖警卫,我想覆盖(重新发送)的整个功能,但我认为这不是最好的解决方案所以谁能告诉我该怎么做
解决方案
而不是覆盖守卫的功能,我只会
shouldUse()
像这样在构造函数中使用函数,
auth()->shouldUse('admin');
然后当我使用request->user()
它时自动将其用作管理员守卫
推荐阅读
- r - 在 R Shiny 中将输出转换为输入
- webpack - 如何在 webpack 中使用锚标签?
- sql - SQL JOINS:我需要在 AdventureWorks2016 中选择 8 到 10 之间的已售订单吗?
- android - Android Espresso 测试错误:没有静态方法 loadSingleServiceOrNull()
- c - 添加多个动态分配的矩阵?
- python - 如何在另一个python文件中的列表中附加一些东西?
- c# - Firebase 存储:如何获取下载链接?C#
- python - 带线程的全局变量和 Tkinter
- javascript - 为什么我按下按钮时标签和文本框会消失?有人能帮我吗
- memory - CentOS 7 显示的内存使用量比报告的多