【问题标题】:Pattern based filter except one route基于模式的过滤器,除了一个路由
【发布时间】:2014-10-10 13:04:57
【问题描述】:

我有这些过滤器

Route::when('app/*', 'auth');
Route::when('app/*', 'filled_basic_info');

如果用户的基本信息尚未填写,“filled_basic_info”过滤器会将用户重定向到“users.personal”路由。

“users.personal”路由指向“app/personal”网址。

我的问题是,如何设置 'filled_basic_info' 过滤器以应用于除 'users.personal' 路由之外的所有通往 'app/*' 的路由?

我试过了

Route::when('app/*', 'filled_basic_info', array('except' => 'users.personal'));

但它不起作用。

我希望避免对所有“app/*”路由进行分组,因为我需要在我现有的所有包上这样做。

谢谢。

【问题讨论】:

    标签: php laravel filter laravel-routing


    【解决方案1】:

    我最终像这样编辑过滤器:

    Route::filter('filled_basic_info', function()
    {
        if (empty(Auth::user()->first_name) || empty(Auth::user()->last_name))
        {
            if(!(Route::currentRouteName() == "user.personal"))
                return Redirect::route('user.personal')->withAlerts(['Please enter your name below to continue.']);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 2019-06-21
      • 2018-12-24
      • 1970-01-01
      • 2021-10-03
      • 2019-04-23
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      相关资源
      最近更新 更多