2
votes

I use Laravel 5.3 and I have named all my routes.

I want to use the route() function and include my $_GET params.

This is what I've tried :

<a href="{{ route('myRoute', ['id' => $id, 'slug' => str_slug($name)], request()->all()]) }}">

Or

<a href="{{ route('myRoute', [array_merge(['id' => $id, 'slug' => str_slug($name)], request()->all())]) }}">

For now, I got this error

ErrorException in UrlGenerator.php line 377: Array to string conversion (View: ....

Is there a way to include all params ? I don't want to list them one by one. Thanks

EDIT

I had en error in my code, now it works with :

<a href="{{ route('myRoute', array_merge(['id' => $id, 'slug' => str_slug($name)], request()->all())) }}">
2

2 Answers

0
votes

request()->all() and ['id' => $id, 'slug' => str_slug($name)] are arrays and you're trying to pass it as string. When you have a lot of data, it's better to pass it using POST method.

0
votes

A cheap hack would be this:

<a href="{{ route('myRoute') . '?' . http_build_query(array_merge(['id' => $id, 'slug' => str_slug($name)], request()->all())) }}">

http_build_query turns an associative array into GET paramaters string (without the starting ?).