【问题标题】:Laravel Show not authorised if user opens admin route如果用户打开管理员路由,Laravel Show 未授权
【发布时间】:2016-02-29 11:07:10
【问题描述】:

这里有两条路线

Route::group(['prefix' => 'admin', 'middleware' => ['role:superAdmin']], function() {
Route::get('/dashboard', 'Admin\AdminController@getDashboard');
});

Route::group(['prefix' => 'user', 'middleware' => ['role:user']], function() {
Route::get('/profile', 'User\UserController@getProfile');
});

如果用户尝试访问 /admin/dashboard 则应显示未授权视图。

【问题讨论】:

  • 您目前遇到什么错误/页面?
  • Application.php 第 882 行中的 HttpException,我需要为此自定义错误页面。

标签: laravel-5.1 laravel-routing


【解决方案1】:

你可以在 Laravel 中拦截异常,然后对它们做任何你想做的事情。在这种情况下,您可以捕获 HTTP 异常,然后显示视图或控制器。

在此处查看render() 方法https://laravel.com/docs/5.1/errors#the-exception-handler

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-19
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 2015-11-09
    • 2018-09-21
    • 2016-04-21
    相关资源
    最近更新 更多