codezero-be / laravel-localized-routes

⭐️ A convenient way to set up and use localized routes in a Laravel app.
MIT License
504 stars 46 forks source link

How to remove route parameters? #80

Closed cod3rshotout closed 1 year ago

cod3rshotout commented 1 year ago

Hi, thanks for your library first of all!

I'm having a problem using Route::localizedUrl, in particular, some routes are defined in this way:

Route::get('/form-and-function', 'Webkul\Shop\Http\Controllers\FrontendController@formAndFunction')->defaults('_config', [
            'view' => 'shop::layouts.pages.form-and-function'
        ])->name('shop.frontend.pages.form_and_function');

so calling localizedUrl will return:

https://example.com/it/form-and-function?_config%5Bview%5D=shop%3A%3Alayouts.pages.form-and-function

is there any way to remove all the parameters from the url and keep only https://example.com/it/form-and-function

Thanks

ivanvermeyen commented 1 year ago

Hi,

This wasn't possible yet, but I've just added an option to exclude the query string:

Route::localizedUrl($locale = null, $parameters = null, $absolute = true, $keepQuery = true);

I'll tag it in a sec.

cod3rshotout commented 1 year ago

@ivanvermeyen thanks for the update but I still have the parameters .. seems the following line should be updated:

if ($url = $this->generateFromNamedRoute($locale, $parameters, $absolute)) {
    dd($url);
    return empty($query) && $keepQuery ? $url . $urlBuilder->getQueryString() : $url;
}

Essentially $url contains this: https://example.com/it/form-and-function?_config%5Bview%5D=shop%3A%3Alayouts.pages.form-and-function. But should contains only: https://example.com/it/form-and-function, so even specifying keepQuery on true, the parameters are still there.

ivanvermeyen commented 1 year ago

Did you set $keepQuery to false to not show the query? If true it will show the query. (which is the default)

cod3rshotout commented 1 year ago

@ivanvermeyen yes, I set it, but as I said generateFromNamedRoute return the url with the query string, so even though $keepQuery is false, I get the parameters. Guess the same parameter should be passed to generateFromNamedRoute

ivanvermeyen commented 1 year ago

Query parameters passed to the function (or defaults in your case) were not removed. Should be fixed now in 2.10.1 👍