批改状态:合格
老师批语:合格
中间件的创建
php artisan make:middleware test\Clk
clk.php文件 handle方法中添加
exit("hello widdleware");
中间件的注册
app\http\kermel.php 文件中 routemiddleware 属性添加
protected $routeMiddleware = [// 自定义中间件'clk' => \App\Http\Middleware\test\Clk::class,];
中间件的触发
web.php中指定路由调用 middleware方法
Route::get('/home', 'home@index')->middleware('clk');
效果图

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号