Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel Middleware to set language from subdomain
namespace App\Http\Middleware;
use Closure;
class SetLanguage
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
$pieces = explode('.', $request->getHost());
if( ($pieces[0] == 'fr') || ($pieces[0] == 'ch')){
session(['locale' => 'fr']);
return $next($request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.