Aug 11, 2016
0
Level 1
Session Issue in Middleware
Session Issue inside Middleware
I can't get the previous session, why its always the same as the $request->getHost();
public function handle($request, Closure $next)
{
$parts = explode('.', $request->getHost());
$subdomain = $parts[0];
/*$domain = DomainList::where('subdomain', '=', $subdomain)->first();
if($domain == null) {
abort(404);
}*/
$res = \DB::select("SHOW DATABASES LIKE '" . $subdomain . "'");
if(count($res) == 0) {
abort(404);
}
if(!\Session::has('subdomain')) {
\Session::put('subdomain', config('database.connections.mysql.database'));
}
if($subdomain <> \Session::get('subdomain')) // ISSUE HERE
{
config(['database.connections.mysql.database'=> $subdomain]);
\DB::reconnect();
}
\Session::put('subdomain', $subdomain);
\Session::save();
return $next($request);
}
Please or to participate in this conversation.