Reputation: 170
I'm using latest Laravel 5.4. My site is configured to use German and English languages. So for instance, I have a login page for German:
http://localhost/de/login
and for English:
http://localhost/en/login
What I've done is I created a Language middleware that looks at the first segment of the URI ('en' or 'de') and sets proper app()->setLocale()
based on the first segment value. What I'm struggling with is how do I generate links (properly / best practice) for such routes. What function should I use in my blade templates to generate such links. I tried route('login', app()->getLocale())
but it's giving me something like this: http://localhost/en/login?de
. Why is this happening? What's the function I should be using to generate links to named routes and unnamed routes?
Thanks, Z
Upvotes: 0
Views: 52
Reputation: 7474
Try this:
Route::post('page/{locale?}', 'PageController@someMethod')->where(['locale' => 'de|en|es|fr|it|nl']);
See, if this works!
Upvotes: 1