【问题标题】:Using rydurham Sentinel on specific route in Laravel 5.1在 Laravel 5.1 的特定路线上使用 rydurham Sentinel
【发布时间】:2025-12-23 13:30:10
【问题描述】:

我在 Laravel 5.1 中使用 Ryan Durham https://github.com/rydurham/Sentinel 的哨兵。

我曾经在 Larvel 4.2 中使用 Confide https://github.com/Zizaco/confide

有了 Confide,我可以像这样为任何路由添加身份验证

// Applies auth filter to the routes within orders/ 
Route::when('orders/*', 'auth');

我已经在 Sentinel 文档中搜索了此功能,但我不知道如何完成此操作。我可以在控制器的构造中为 adminuser 设置身份验证,但我需要在特定路由上具有特定的身份验证能力。

我的问题是,我如何以与 Confide 相同的干净方式使用 rydurham sentinel 将 user 重定向到仅用于 admin 的路线?

【问题讨论】:

    标签: authentication laravel-5.1


    【解决方案1】:

    您应该在路由上使用哨兵中间件。像

    Route::get('orders', ['middleware' => 'sentry.admin', function () {
        // return view;
    }]);
    

    【讨论】: