Route::filter('age', function($route, $request, $value){
return ($value>=40);
});
Route::filter('auth', function(){
return (Input::get('auth')=='yes');
});
Route::get('barx', array('before' => 'age:40|auth', function(){
return 'Hello World';
}));
我应该拨打什么网址来接触'Hello World'
我正在尝试http://laravel/barx?auth=yes
但是它不能正常工作
答案 0 :(得分:1)
自己弄清楚。
/*
filter accept only two arguments, second is closure.
filter always send a string/Redirect as a response. Can't be a boolean
If any of filter return a string then it will be consider an exit.
::EXAMPLE BELOW::
*/
Route::filter('old', function(){if(Input::get('age')>=50)return "Old";});
Route::filter('adult', function($route, $request, $value){if($value>=18)return "adult"; });
Route::get('barx', array('before' => 'old|adult:18', function(){return 'You are a child';}));
现在尝试网址http://laravel/barx?age=12
以及当前代码中代码adult:18
中成人的更改值
如果您放置adult below 18
和age below 50
,则会说“您还是小孩”