Redirect unauthorized user Laravel

Asked

Viewed 315 times

3

When a page that is with the middleware auth attempts to be accessed by an unauthenticated user, Laravel redirects it to the 'login' route. How to change this so it redirects to another route?

1 answer

4

Inside your project on the way app/Http/Middleware there will be a file called Authenticate.php.

In function redirectTo() you must change the return line of the function, with the route you want.

For example, you want to change the route of login for register. We will exchange:

protected function redirectTo($request){
    if (! $request->expectsJson()) {
        return route('login');
    }
}

For:

protected function redirectTo($request){
    if (! $request->expectsJson()) {
        return route('register');
    }
}

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.