首页 > 其他分享 >laravel:中间件给controller传递参数(10.27.0)

laravel:中间件给controller传递参数(10.27.0)

时间:2023-10-23 14:34:14浏览次数:49  
标签:laravel use 10.27 中间件 request controller https com

一,相关文档

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

相关文章

  • 视频直播系统源码,在Laravel中自定义模板函数 并在模板中调用
    视频直播系统源码,在Laravel中自定义模板函数并在模板中调用第一步:在app/bootstrap下定义一个php文件 diy_helpers.php​内容如下: <?phpfunctioncssVersion($data){  $version="1.01";  return$data."?v=".$version;}functionjsVersion($data){  $ver......
  • laravel:单元测试之http测试(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/http-tests/14896二,php代码:1,创建test程序liuhongdi@lhdpc:/data/laravel/dignews$phpartisanmake:testNewsTest   INFO  Test[tests/Feature/NewsTest.php]createdsuccessfully.2,代码:12345......
  • laravel:编写命令行脚本(10.27.0)
     一,相关文档https://learnku.com/docs/laravel/10.x/artisan/14859二,php代码1,创建commandliuhongdi@lhdpc:/data/laravel/dignews$phpartisanmake:commandCart   INFO  Consolecommand[app/Console/Commands/Cart.php]createdsuccessfully.2,command的代......
  • laravel:路由组(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/routing/14845二,查看所有注册的路由1,查看路由:liuhongdi@lhdpc:/data/laravel/dignews$phpartisanroute:listGET|HEAD/......................................................................................
  • laravel:blade模板(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/blade/14852二,创建controller和view1,创建controllerliuhongdi@lhdpc:/data/laravel/dignews$phpartisanmake:controllerCommentController   INFO  Controller[app/Http/Controllers/CommentController.php......
  • laravel:服务容器(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/container/14842二,php代码:假设我们有两种商品:虚拟商品如账号,实体商品如手办需要销售1,App\extend\mall\GoodsInterface.php1234567<?phpnamespaceApp\extend\mall;//接口interfaceGoodsInterfa......
  • laravel:服务提供者(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/providers/14843二,php代码:1,业务代码:App\extend\mall\GoodsInterface.php1234567<?phpnamespaceApp\extend\mall;//接口interfaceGoodsInterface{    publicfunctionsale();}......
  • laravel:捕捉异常记录到日志(10.27.0)
    一,相关文档:https://learnku.com/docs/laravel/10.x/errors/14857#9e8f93二,php代码:1,代码:12345678910111213141516171819202122232425262728classNewsControllerextendsController{    //启用事务    publicfuncti......
  • laravel:定时任务(10.27.0)
    一,相关的文档:https://learnku.com/docs/laravel/10.x/scheduling/14875二,php代码:1,创建command:liuhongdi@lhdpc:/data/laravel/dignews$phpartisanmake:commandOrderStatus   INFO  Consolecommand[app/Console/Commands/OrderStatus.php]createdsucces......
  • laravel:使用tinker(10.27.0)
    一,启动与退出:liuhongdi@lhdpc:/data/laravel/dignews$phpartisantinkerPsyShellv0.11.22(PHP8.1.1—cli)byJustinHileman>exit   INFO  Goodbye.二,查询数据liuhongdi@lhdpc:/data/laravel/dignews$phpartisantinkerPsyShellv0.11.22(PHP8.1.......