Hey, Just started Laravel today and I was checking some tips and tricks on how to make a multilanguage site. But the guide don't seem to be correct for Laravel 5.0. What I wanted to do can be seen on this page link to forum post Searched the entire project with Sublime but the filters.php seems to be gone.
Were shall i put the before statements in L5? Thanks for any help.
App::before(function($request) { if (Session::has('lang')) { App::setLocale(Session::get('lang')); } else { Session::put('lang', Config::get('app.locale')); } });
It depends where in the request cycle you want this to be set and where you want this data to be accessed. Most of the times putting it in the boot method of the AppServiceProvider will do, but sometimes it should better be placed in a route middleware (for example if you want to be able to group routes for multilanguage setup).
The following SO question has two answers, one with an example using a ServiceProvider and another using a Middleware.
http://stackoverflow.com/questions/28356193/laravel-5-share-variables-in-service-providers
filter in laravel 5 change to middleware, you can read :
http://stackoverflow.com/questions/26373850/filters-in-laravel-5 http://mattstauffer.co/blog/laravel-5.0-middleware-filter-style
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community