新建中间件
<?php
namespace App\Http\Middleware;
use Closure;
class activity
{
public function handle($request, Closure $next)
{
if(time()< strtotime('2017-05-24')){
return redirect('student/activity0');
}
if(time()>strtotime('2017-05-23'))
{
return redirect('student/activity2');
}
return $next($request);
}
}
注册中间件
如果想注册全局中间件写在这里
我们这里写在这就可以
使用中间件
Route::get('student/activity0','StudentsController@activity0');
Route::get('student/activity2','StudentsController@activity2');
Route::group(['middleware'=>['activity']],function(){
Route::get('student/activity1','StudentsController@activity1');
});
/**
* 活动开始前
*/
public function activity0()
{
return '活动即将开始,敬请期待!!';
}
/**
* 活动开始
*/
public function activity1()
{
return '活动进行时!!';
}
/**
* 活动结束
*/
public function activity2()
{
return '活动已结束!!';
}