laravel - 自定义拒绝访问警告
问题描述
如果您没有正确的角色,如何正确重定向此访问禁令?通知非常简单,显示错误,我希望它通过通知重定向到家。
namespace jeremykenedy\LaravelRoles\App\Exceptions;
class RoleDeniedException extends AccessDeniedException
{
/**
* Create a new role denied exception instance.
*
* @param string $role
*/
public function __construct($role)
{
$this->message = sprintf("You don't have a required ['%s'] role.", $role);
}
}
解决方案
覆盖类render
的函数RoleDeniedException
。
/**
* Render the exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function render($request)
{
return redirect('home');
}
有关更多详细信息,请参阅以下链接;
推荐阅读
- python - 无法使用请求连接到 Tor,而我使用 selenium 也是如此
- firebase - firebase 实时数据库:TypeError:无法将未定义或 null 转换为对象
- javascript - 如何在 javascript 中将 jQuery 的值分配给 PHP SESSION
- c# - 为什么要创建父类的类型来存储子类的对象?
- python - 我们可以将 fastText 与 SVM 一起集成吗?
- javascript - 在nodejs中通过带有构造函数的模块公开多个对象
- go - 如何在 Go 语言的模板中获取嵌入变量
- java - 本机库 D:\jdk 1.8.0 181\jre1.8.0_181\bin\glass.dll 已在另一个类加载器中加载
- actions-on-google - 启用智能显示器
- docker - 无法从 Jenkins 管道连接远程 docker 主机 api