Reputation: 24061
Im using the Auth controller in Laravel along with the auth middleware.
If the user is not logged in it redirects to:
auth/login
But I wish to redirect to a different url.
I have this in my auth controller:
protected $loginPath = '/cms/login';
protected $redirectTo = '/cms';
But it still redirects to:
auth/login
How can I redirect the auth controller?
Upvotes: 0
Views: 177
Reputation: 136
Redirection will be handled by middleware. Hence change the redirect under handle() method in auth middleware as follows:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest())
{
if ($request->ajax())
{
//return response('Unauthorized.', 401);
}
else
{
//return redirect()->guest('auth/login');
return redirect()->guest('cms/login');
}
}
return $next($request);
}
Upvotes: 1
Reputation: 9883
The path for the redirect when you're not logged in is handled in the authenticates middleware, which is found at app/Http/Middleware/Authenticate.php
.
Upvotes: 2