一,相关文档
https://learnku.com/docs/laravel/10.x/middleware/14846
二,php代码
1,middleware
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use App\extend\result\Result;
class CheckIp
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request , Closure $next ): Response
{
//添加和修改参数
$request ->merge([ 'name' => '谢广坤' ]);
$request ->merge([ 'address' => '象牙山' ]);
return $next ( $request );
}
}
|
2,controller
1 2 3 4 5 6 7 8 |
//显示请求结果
public function req(Request $request ){
//所有参数
$params = $request ->all(); #获取所有参数
return [ 'code' =>0,
'params' => $params ,
];
}
|
说明:刘宏缔的架构森林—专注it技术的博客,
网站:https://blog.imgtouch.com
原文: https://blog.imgtouch.com/index.php/2023/10/23/laravel-zhong-jian-jian-gei-controller-chuan-di-can-shu/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: [email protected]
三,测试效果:
四,查看laravel框架的版本:
liuhongdi@lhdpc:/data/laravel/dignews$ php artisan --version
Laravel Framework 10.27.0
标签:laravel,use,10.27,中间件,request,controller,https,com
From: https://www.cnblogs.com/architectforest/p/17782321.html