标签:loading route and group str ret request @param ons
过滤进入应用程序的http请求。
比如,有一个活动,在活动开始前进入活动页则跳转到宣传页
php artisan make:middleware Activity
<?php namespace App\Http\Middleware; use Closure; class Activity { /** * Handle an incoming request. * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request,Closure $next){ if(time() < strtotime(‘2020-08-06‘)){ return redirect(‘activity0‘); } return $next($request); } }
public function activity0() { return ‘活动快要开始了‘; } public function activity1() { return ‘活动进行中,感谢你的参与1‘; } public function activity2() { return ‘活动进行中,感谢你的参与2‘; }
//宣传页面 Route::any(‘activity0‘,[‘uses‘=>‘StudentController@activity0‘]); //活动页面: Route::group([‘middleware‘=>[‘activity‘]],function (){ Route::any(‘activity1‘,[‘uses‘=>‘StudentController@activity1‘]); Route::any(‘activity2‘,[‘uses‘=>‘StudentController@activity2‘]); });
protected $routeMiddleware = [ 。。。。。 ‘activity‘ => \App\Http\Middleware\Activity::class, ];
public function handle($request,Closure $next) { echo ‘【我是前置操作】‘; $response = $next($request);//$next($request)本质上就是response echo($response); echo ‘【我是后置操作】‘; }
$next($request)就是response 在此之间的就是前置操作,后面的就是后置操作。。。。。
标签:loading route and group str ret request @param ons
原文地址:https://www.cnblogs.com/polax/p/13323707.html