Reputation: 495
I have complicated route system, there is short example:
Route::group(['domain' => '{country}'], function () {
Route::get('/{category}/{brand}/{Gender?}-{FrameShape?}-{FrameType?}-{FrameColor?}-{LenseColor?}-{PriceRange?}-{FrameMaterial?}-{LensMaterial?}-{TryOn?}-{View360?}-{FastShipping?}-{SortBy?}-{Page?}-{Clearance?}-{NewArrival?}-{Size?}-{Prescription?}-{Polarized?}-{AsianFit?}', 'BrandController@index')
->name('brand');
});
This is filter page, and there could be a lot parameters. For example user can open this url:
http://site_us.com/glasses/Adidas/Women------------------
It means that user opens US domain (website have a lot of countries), category "glasses", brand "Adidas", and in filter gender is Women . And on this page I'm trying to generate new URL, e.g. with gender is Men, write something like that:
route('brand', ['Gender' => 'Men']);
// result: http://Men/------------------
So, system lost country domain, category, brand, even slashes. I expected that system already know current parameters, and I need just pass changed parameter and have beautiful code.
What the right way to do this?
Upvotes: 1
Views: 524
Reputation: 3971
" I expected that system already know current parameters, and I need just pass changed parameter and have beautiful code."
The system does know the parameters, but the thing it does not know is, whether or not you want to reuse them.
You can explicitly pass parameters like:
route('brand', [
'category' => 'your_category',
'brand' => 'your_brand',
'Gender' => 'Men'
]);
or from the request params:
route('brand', [
'category' => app('request')->category, // using app() helper to resolve dependency in View
'brand' => app('request')->brand,
'Gender' => 'Men'
]);
But remember - that is just a direct solution to answer your question, and not something I am recommending.
Upvotes: 1