1,创建中间件
php artisan make:middleware Activery
2,中间写过滤
public function handle($request, Closure $next)
{
if($request->age<20){
return redirect('home');
}
return $next($request);
},
3,注册中间件kernel
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'activery' => \App\Http\Middleware\Activery::class,
];
4,路由加中间件
Route::group(['middleware'=>['activery']],function(){标签:laravel,HTTP,Middleware,中间件,Auth,Routing,Illuminate,class From: https://www.cnblogs.com/96net/p/17808753.html
Route::any('lites/{age?}','StudentController@lites');
});