Tuesday, March 7, 2017

Links for routes with prefixes

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



via zoltalar

Advertisement