duanjia9577 2018-06-12 12:04
浏览 146
已采纳

将get参数添加到laravel的重定向方法中

I use laravel 5.6

I have GET parameter which I want to pass to redirect function.

Route::get('/about', function () {
   //I want to add param to this redirect function
   return redirect('/en/about');
});

if the route looks like /about?param=123 after redirect the param will be lost. is there way to add parameter to redirect method? as I see this function doesn't include input parameters. the parameter is optional, so it may not be provided. maybe there's way to override this function? or some other solution? all suggestions will be appreciated

UPDATE

is it possible to override the redirect() method ? I think in my case it will be the best solution

  • 写回答

6条回答 默认 最新

  • drfm55597 2018-06-12 12:11
    关注

    You have to get the parameter in the URL and pass it to redirect method in an array

    Route::get('/about/{param}', function () {
       return \Redirect::route('/en/about', ['param'=>$param])
    });
    

    without having to use named route

    Route::get('/about/{param}', function () {
       return redirect('/en/about', ['param'=>$param])
    });
    

    For optional parameter

    Route::get('/about/{param?}', function ($param = 'my param') {
       return redirect('/en/about', ['param'=>$param])
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?