In Laravel 4.2 I had this before filter that set the Eloquent model and table based on the URL (admin.example.com vs example.com)
Here is my filter code:
App::before(function($request)
{
// Check if we are using the admin URL
$host = $request->getHost();
$parts = explode('.', $host);
if ($parts[0] == 'admin')
{
// Set the config for user info (not sponsor)
Config::set('auth.model', 'Admin');
Config::set('auth.table', 'admins');
}
});
I tried creating 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 am setting the controller that is called based on the auth.model setting like this:
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');
What I found is that the routes are all read prior to the middleware so the change I am trying to make through Config::set() isn't happening. I am only getting the value that is set in the auth.php config file.
What am I doing wrong and how should I do this in Laravel 5?