drehimself / laravel-language-switcher-example

http://usefullaravelpackages.com
12 stars 15 forks source link

Missing required parameter for the routes that require more than the prefix #4

Closed mirasoil closed 3 years ago

mirasoil commented 3 years ago

Hi ! I've been struggling lately with this problem and I really need some help.

So I implemented this language-switcher component and everything is working perfectly except the routes that requires more than two parameters, such as the id or slug or anything else besides the language prefix. I saw that there is a possible fix for this by using URL Generator macro which will do the work but I really have to stick to this this url format: "example.com/en/shop" which in the case of the URL Generator will become: "example.com/shop?lang=en". That would be too much to modify for me since I no longer have time and I have no idea how to override this method in order to generate just the locale parameter as the first segment, not as a value for some other variable.

Also, I tried added an optional parameter in the language-switcher component like so <language-switcher locale="{{ app()->getLocale() }}" link-fr="{{ route(Route::currentRouteName(), ['locale' => 'fr', 'id' => '/{id?}']) }}" link-en="{{ route(Route::currentRouteName(), ['locale' => 'en','id' => '/{id?}']) }}"></language-switcher> but the result is the same, it does work for routes with 2 parameters but when using resource group where some of the routes requires 3 parameters it cracks.

I would appreciate any piece of advice since I no longer have any ideas on how this problem could be fixed.

Here is the code from the URL Generator: #https://stackoverflow.com/questions/62607673/laravel-language-switcher-pass-additional-parameters-to-a-route

Thank you !

mirasoil commented 3 years ago

Solved by https://stackoverflow.com/questions/67207509/missing-required-parameter-routes-with-more-than-2-parameters-are-not-working