Missing required parameters but i'm passing them with a middleware
The routes file defines the routes for my users subdomain, so I need to pass the {subdomain} variable to every route. I made a simple middleware to achieve this:
public function handle($request, Closure $next)
{
URL::defaults([
'subdomain' => $request->subdomain
]);
return $next($request);
}
The problem is that when i add the Auth routes to the file, the missing parameter error appears:
Auth::routes(['verify' => true]); // Error missing parameter for route 'login'
If i print the php artisan route:list, the middleware is also applied to the auth routes. Why is it still complaining?
I did a bit more of research and I'm posting the solution for anyone with the same problem.
Basically, the error was with the Authenticate.php middleware. Just change this:
// Change this:
class Authenticate extends Middleware
{
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
// To this (where $request->domain is what you set in your routes as '{domain}'):
class Authenticate extends Middleware
{
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login', [
'domain' => $request->domain
]);
}
}
}