1-4Controller之Middleware
1.注册中间件:
新建中间件文件:Activity
<?php namespace App\Http\Middleware; use Closure; class Activity{ public function handle($request,Closure $next){ if (time()<strtotime('2018-02-25')){ return redirect('activity0'); } return $next($request); } }
在Kernel中注册中间件:
'activity' => \App\Http\Middleware\Activity::class,
路由:
//宣传页面 Route::any('activity0',['uses'=>'StudentController@activity0']); //活动页面: Route::group(['middleware'=>['activity']],function (){ Route::any('activity1',['uses'=>'StudentController@activity1']); Route::any('activity2',['uses'=>'StudentController@activity2']); });
控制器:
//活动的宣传页面: public function activity0(){ return "活动快要开始了,敬请期待"; } //活动的宣传页面: public function activity1(){ return "互动进行中001"; } //活动的宣传页面: public function activity2(){ return "互动进行中002"; }