John Stamoutsos
John Stamoutsos

Reputation: 191

Laravel how can make a query string but not like url path?

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

Upvotes: 0

Views: 99

Answers (2)

John Stamoutsos
John Stamoutsos

Reputation: 191

The answer is:

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

Upvotes: 0

Alexey Mezenin
Alexey Mezenin

Reputation: 163748

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'

Upvotes: 2

Related Questions