Laravel Pass Parameter from Route to Filter

旧街凉风 提交于 2019-12-02 21:51:06

Filters can be passed parameters, like the Route object or the Request:

Specifying Filter Parameters

Route::filter('age', function($route, $request, $value)
{
    //
});

Above example is taken from the docs: http://laravel.com/docs/routing#route-filters

Once you're inside the closure, you take the parameter from the $route:

Route::filter('test_filter', function($route) {
    $param = $route->getParameter('param'); // use the key you defined
    return "The value is $param";
});


Alternatively, I believe you can just fetch the segment you need (not tested but should work):
Route::filter('test_filter', function() {
    $param = Request::segment(1);
    return "The value is $param";
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!