Laravel adds a URI to the route

Hi, I want to add uri to the laravel route function.

For example, do we have / search? type = listing

//how do i can achieve this with 

route('search',['type'=>'listing'])

As soon as we are in search. I want all variables to be added for search, e.g.

type=listing&query=blah blah

+4
source share
2 answers

If you understand correctly, you want to save all query parameters. Use Request::query()to get it, and then merge with the new options.

route('search', array_merge(\Request::query(), ['type' => 'listing'])));
+2
source

If you have a named route and you want to generate a url with query parameters, then:

route('route_name', ['param1' => 'value', 'param2' => 'value']);

In your case, you can do this with

route('search',['type'=>'listing','subject' => ['blah'],[....]])
0
source

Source: https://habr.com/ru/post/1679608/


All Articles