我有一个路由组,我将通过中间件检查用户的等级:
Route::group(['prefix' => 'expert'], function () {
Route::group(['prefix' => 'partner', 'middleware' => 'rank:4,5'], function () {
Route::get('/search', 'PartnerController@getSearch');
Route::post('/result', 'PartnerController@postSearch');
});
});
中间件在kernel.php中注册:
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'rank' => \App\Http\Middleware\checkRank::class,
];
这是我的班级:
namespace App\Http\Middleware;
use Closure;
use Auth;
class checkRank {
public function handle($request, Closure $next, $ranks) {
//return $next($request);
return print_r($ranks);
}
}
我想看到的是具有值[4,5]
的数组但我得到的只是4
PHP-Version是5.6.11
按照以下方式尝试:http://laravel.com/docs/5.1/middleware#middleware-parameters
答案 0 :(得分:10)
public function handle($request, Closure $next, ...$ranks) {}
我忘记了$ rank前面的三个点