AppLanguage.php 775 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. use App;
  5. class AppLanguage
  6. {
  7. /**
  8. * Handle an incoming request.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @param \Closure $next
  12. * @return mixed
  13. */
  14. public function handle($request, Closure $next)
  15. {
  16. // Check header request and determine localizaton
  17. if($request->hasHeader('App-Language')){
  18. $locale = $request->header('App-Language');
  19. }
  20. elseif(env('DEFAULT_LANGUAGE') != null){
  21. $locale = env('DEFAULT_LANGUAGE');
  22. }
  23. else{
  24. $locale = 'en';
  25. }
  26. // set laravel localization
  27. App::setLocale($locale);
  28. // continue request
  29. return $next($request);
  30. }
  31. }