samedi 26 novembre 2016

Laravel locale middleware not working for all routes & locale session destroys after logout

I am working Multilanguage website. I have created a middleware for locale

Laravel 5.3 routes/web.php

Route::group(['middleware' => 'locale'], function(){
    Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index');

});

Route::get('setlocale/{locale}', function($locale){
     \Session::put('locale', $locale);
     return back();
}); 

Locale is working fine with Home, Login & Registration view But not working fine with auth/passwords/reset.blade.php and auth/passwords/email.blade.php

Middleware: locale

<?php

namespace Onebook\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Config;

class Locale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {   
        $locale = 'en';
        if(Session::has('locale')){
            $locale = Session::get('locale');
        }
        else{
            $locale = Config::get('app.locale');
        }
        \App::setlocale($locale);
        return $next($request);
    }
}

When I press logout the Locale session destroys.

Thank in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2gtGCrI
via IFTTT

Aucun commentaire:

Enregistrer un commentaire