chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
401 stars 25 forks source link

Default Locale Index Route? #18

Closed baminc closed 4 years ago

baminc commented 4 years ago

It seems like its not possible to have the default route "/" redirect to a the default locale route.

For example my app has german "de" and english "en", german is default locale, the routes generated by: Route::multilingual('/', 'MainController@index')->name('index');

only include "/" and "/en" but not "/de". Any way to force the routing to create a locale based route for all routes including the default route? And then also redirect "/" to "/LOCALE"?

chinleung commented 4 years ago

Hi @baminc,

You can add the following in your .env file to prefix the default locale:

MULTILINGUAL_ROUTES_PREFIX_DEFAULT=true

Otherwise, you can publish the config and update the value of prefix_default to true.

After you've updated the config, the generate routes should prefix even the default locale, so you will have a /de and a /en route.

Then simply add the following to your routes/web.php for the redirection:

Route::redirect('/', locale());

Also make sure you've updated to v1.4.3 because it was not prefixing the home page previously.

baminc commented 4 years ago

Thanks for the Fix!