StudentController.php中的成员方法
public function activity0()
{
return '活动即将开始,敬请期待';
}
public function activity1()
{
return '活动火爆进行中';
}
public function activity2()
{
return '活动已结束,再见';
}
写中间件App\Http\Middleware/activity.php
namespace App\Http\Middleware;
use Closure;
class activity {
public function handle($request, Closure $next) {
if(time() < strtotime('2022-02-07')){
return redirect('activity0');
}
return $next($request);
}
}
注册中间件app/Http/kernel.php protected $routeMiddleware 下添加
'activity' => \App\Http\Middleware\activity::class,
使用中间件,在路由中添加
Route::get('activity0', 'studentcontroller@activity0');
Route::group(['middleware'=>['activity']],function(){
Route::get('activity1', 'studentcontroller@activity1');
Route::get('activity2', 'studentcontroller@activity2');
});
|