0

I'm trying to make an url query string with laravel but this method:

url()->to('categories', ['id' => 1, 'name' => 'cars']);

Returns me:

http://localhost/categories/1/cars

But I need this:

http://localhost/categories?id=1&name=cars

2 Answers 2

2

First of all, you'll need to create a named route without parameters:

Route::get('categories', ['as' => 'categories', 'uses' => 'SomeController@showCategories']);

Then use route() helper:

route('categories', ['id' => 1, 'name' => 'cars']);

This will generate:

'/categories?id=1&name=cars'
Sign up to request clarification or add additional context in comments.

3 Comments

No! this function need to have a route on my routes/web.php file. It is not working like this. i have make my router class. Something else?
For example Route::any(Request::path(), 'Extender@xRun');
@JohnStamoutsos it's working as expected when you put the route into the routes.php, I've just tested it and it creates exactly URL you need.
0

The answer is:

Route::any(Request::path(), ['as' => Request::path(), 'uses' => 'Extender@xRun']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.