I need to create an app with multiple locales. And each route is prefixed with the locale. For example, xxx.com/en/home
, xxx.com/fr/home
.
The thing is, I need to dynamically bind the locale string to route prefix. Since users can change locale, the locale string is stored in session. And I need reference to the session on web.php. Session object can't be used in the globle scope on web.php, meaning session('key') won't get you anything (null) in the outermost scope except in route functions because Laravel parses web.php before instantiating any session object, I think. Therefore I face a conundrum in that I can't reference session in the outermost scope on web.php while I need session to create dynamic prefix. How can I solve this?
session()
helper for anywhere in the app. – usrNotFound