chinleung / laravel-multilingual-routes

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

Route constrains in different locale #40

Closed chinleung closed 4 years ago

chinleung commented 4 years ago

Let's say for instance we have the following translation in the routes file:

return [
    'single-blog' => '{category}/{post}',
];

It is possible to constrain route parameters at the current time like this:

Route::multilingual()->where('category', 'food|music|aliments|musique');

This will allow the following routes:

https://example.test/food/slug-of-my-post
https://example.test/music/slug-of-my-post
https://example.test/aliments/slug-of-my-post
https://example.test/musique/slug-of-my-post
https://example.test/fr/food/slug-of-my-post
https://example.test/fr/music/slug-of-my-post
https://example.test/fr/aliments/slug-of-my-post
https://example.test/fr/musique/slug-of-my-post

However, in the english version of the website, we don't really want aliments or musique in the available categories. As for the french version, we wouldn't want food or music in the constrains.

chinleung commented 4 years ago

It is now possible to pass a locale as the third parameter when using the where method to apply the constraint only for a specific locale as of v2.7.0 and v1.10.0.

Route::multilingual()->where('category', 'food|music', 'en')->where('category', 'aliments|musique', 'fr');