middleware
<?php
namespace App\Http\Middleware;
use Closure;
class localization
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if(\Session::has('locale')){
\App::setLocale(\Session::get('locale'));
}
return $next($request);
}
}
route
Route::get('locale/{locale}', function($locale){
Session::put('locale',$locale);
return redirect()->back() ;
});
view
<html lang="{{app()->getLocale()}}">
<a href="locale/en">en</a>
<a href="locale/ar">ar</a>
<h1>@lang('home.title')</h1>
</html>
The buttons redirect to the same page without any change. When I change the default language in the file app.php, this changes the language but I need to change it dynamically.