Language.php 618 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use App;
  5. use Session;
  6. use Config;
  7. class Language
  8. {
  9. /**
  10. * Handle an incoming request.
  11. *
  12. * @param \Illuminate\Http\Request $request
  13. * @param \Closure $next
  14. * @return mixed
  15. */
  16. public function handle($request, Closure $next)
  17. {
  18. if(Session::has('locale')){
  19. $locale = Session::get('locale');
  20. }
  21. else{
  22. $locale = env('DEFAULT_LANGUAGE','en');
  23. }
  24. App::setLocale($locale);
  25. $request->session()->put('locale', $locale);
  26. return $next($request);
  27. }
  28. }