【问题标题】:How to use any one of multiple filters in route in Laravel 4.2如何在 Laravel 4.2 的路由中使用多个过滤器中的任何一个
【发布时间】:2016-01-21 10:01:33
【问题描述】:

我正在 Laravel 4.2 中开发我的应用程序。我的应用程序中有 2 个过滤器,名为 guestadmin。管理员可以访问所有控制器,而访客只能访问少数控制器。

这是管理员的路线

Route::group(array('before' => 'admin'), function() 
{
    \\controller functions
});

但我想为客人路由功能。我是这样尝试的

 Route::group(array('before' => 'admin'|'guest'), function() 
    {
        \\some controller functions
    });

但是这种类型的路由会检查两个过滤器...但是我需要检查用户是Admin or Guest 我将如何配置路由?谁能帮忙??

【问题讨论】:

  • 你想用第二个版本实现什么?据我了解,如果是访客或管理员,请执行这些操作。不加过滤器也是一样。
  • 如果我没有添加任何过滤器,那么我将如何限制特定用户的功能??
  • 具体用户是什么意思?
  • Admin 和Guest 是两种类型的用户.... Admin 可以访问所有功能...但是guest 用户被限制访问其中一些功能...

标签: laravel laravel-4


【解决方案1】:

制作第三个过滤器,它将检查用户是访客还是管理员,例如名称是guestOrAdmin。 不如写这样的代码:

Route::group(array('before' => 'guestOrAdmin'), function() 
{
    \\all your controller functions which can be accessed by guests and admins
     Route::group(array('before' => 'guest'), function() 
    {
        \\some controller functions which can be access only by guest
    });
  Route::group(array('before' => 'admin'), function() 
    {
        \\some controller functions which can be access only by admin
    });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    • 2018-10-27
    • 2014-06-07
    • 2021-11-24
    • 2015-07-30
    • 2016-04-30
    • 2012-11-19
    相关资源
    最近更新 更多