FULL STACK DEV
FULL STACK DEV

Reputation: 15941

Laravel append URI in route

Hi I want to append the uri in laravel route function.

e.g we have /search?type=listing

//how do i can achieve this with 

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

Once the we are on the search. I want to have all the variable appended to search like

type=listing&query=blah blah

Upvotes: 9

Views: 5312

Answers (2)

Andrii Lutskevych
Andrii Lutskevych

Reputation: 1379

If I get you right, you want to save all query parameters. Use Request::query() to get it and then merge with your new parameters.

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

Upvotes: 9

Rahul
Rahul

Reputation: 2474

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

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

In your case you can do this with

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

Upvotes: 2

Related Questions