In Laravel 4.2, I had this before the filter, which set the model and Eloquent table based on the URL (admin.example.com vs example.com)
Here is my filter code:
App::before(function($request)
{
$host = $request->getHost();
$parts = explode('.', $host);
if ($parts[0] == 'admin')
{
Config::set('auth.model', 'Admin');
Config::set('auth.table', 'admins');
}
});
I tried to create middleware for this in laravel 5 and have this code:
class AdminOrSponsor implements Middleware {
public function handle($request, Closure $next)
{
$host = $request->getHost();
$parts = explode('.', $host);
if ($parts[0] == 'admin'){
Config::set('auth.model', 'Admin');
Config::set('auth.table', 'admins');
}
return $next($request);
}
}
In my routes.php file, I install a controller that is called based on the auth.model parameter, for example:
Route::get('/auth/login', Config::get('auth.model') . 'Controller@getLogin');
Route::post('/auth/login', Config::get('auth.model') . 'Controller@postLogin');
Route::get('/auth/logout', Config::get('auth.model') . 'Controller@getLogout');
I found that all routes were read before middleware, so the change that I am trying to do through Config :: set () does not occur. I get only the value set in the auth.php configuration file.
What am I doing wrong and how do I do this in Laravel 5?