I want to set a session based on the URL (like http://de.domain.com or http://es.domain.com) before anything in Laravel loads and thought to do this in the ConfigServiceProvider:
public function boot() {
// set language
$parse = parse_url(url());
$url_array = explode('.', $parse['host']);
if($url_array[0] == 'domain' || $url_array[0] == 'www') {
Session::put('current_language', Language::where('short', 'EN')->get());
App::setLocale('en');
} else {
Session::put('current_language', Language::where('short', strtoupper($url_array[0]))->get());
App::setLocale($url_array[0]);
}
}
But this is not working at all. Setting it in the Routes sets the session, but after pages are loaded and thus working on the next page, instead on the current one.
What's the best approach? Cause setting it in the Routes is surely not a good idea
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Nq4XHn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire