Ad

How To Pass Query Parameter Using Route Name In Laravel?

- 1 answer

I know this one

{{route('editApplication', ['id' => $application->id])}} == /application/edit/{id}

But I need

?? == /application/edit?appId=id

Anyone, please replace the "??" with your answer that helps me out.

Ad

Answer

It depends how you route looks like:

If you route is:

Route::get('/application/edit/{id}', 'SomeController')->name('editApplication');

when you use

route('editApplication', ['id' => 5])

url will be like this:

/application/edit/5

However all other parameters (that are not in route parameters) will be used as query string so for example:

route('editApplication', ['id' => 5, 'first' => 'foo', 'second' => 'bar'])

will generate url like this:

/application/edit/5?first=foo&second=bar

In case you want to achieve url like this

/application/edit?appId=id

you should define route like this:

Route::get('/application/edit/', 'SomeController')->name('editApplication');

and then when you use

route('editApplication', ['appId' => 5])

you will get

/application/edit?appId=5

url.

Ad
source: stackoverflow.com
Ad