Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

croftCoder's avatar

Laravel Pass Current Request Query String To Another Controller Method

i have a list of members i would like to export based on parameters in the current url request query string. for example, in the members_list page, /members?gender=men&day-born=friday. i can already generate and download the data doing so: /export?gender=men&day-born=friday

how do i generate the export route keeping the current members_list page url request query string and download the data without leaving the members_list page?

0 likes
4 replies
devingray_'s avatar
$string = Str::after(url()->previous(), '?');
OR
$string = $request->getQueryString();
croftCoder's avatar

@devingray_ the first line gets the query string, but i want to pass that as the request object, like the previous request object passed to another controller method. also the route /members?gender=men&day-born=friday should become /export?gender=men&day-born=friday as the export route.

devingray_'s avatar
Level 8

@croftCoder Without your code it would be super hard to help you.

class ExampleController
{
   public function doTheThing(Request $request)
   {
        $string = Str::after(url()->previous(), '?');
       // Do the thing with the string here
      // I guess
      return redirect()->intended('/export?' . $string);
   }
}

Please or to participate in this conversation.