Created
April 6, 2021 11:49
-
-
Save zoparga/f2dfc5f5b13d5d29de278220c277be48 to your computer and use it in GitHub Desktop.
Laravel localize middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\App; | |
class SetLanguage | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle(Request $request, Closure $next) | |
{ | |
$domain = parse_url($request->url(), PHP_URL_HOST); | |
if ($domain == 'www.asd.hu' || $domain == 'asd.hu') { | |
$language = 'hu'; | |
} else { | |
$language = 'en'; | |
} | |
//View::share('language', $language); // Could be useful in views? | |
App::setLocale($language); | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment