I designed a site with Laravel. now I want add new language to it.I read laravel document . It was good but I have a problem.suppose I have a page that show detail of products so I have a route like mysite.com/product/id that get product’s id and show it.also I have a method in controller like
public function showProduct($id){
...
}
If I add new Language , the route will change to this: mysite/en/product/id
now I must change my method because now two parameter send my method.something like this :
public function showProduct($lang,$id){
...
}
So two problems arise:
- I must change all method in my site which is time consuming
- I do not need language parameter in methods because I set $locan via middleware
pay attention that I do not want remove for example en from my URL (because of SEO)
2
Answers
Something like
Or
Open your
RouteServiceProvider
and say that language parameter actually is not a parameter, it’s a global prefix.here is sample language middleware, but it’s need to be improve
So in your controller, or in your routes. you don’t have deal with language parameter