简体   繁体   中英

Laravel protecting routes not working

This is my controller for my login and logout route.

I want the guest to be able to view every route except the destroy route. But it is not working. The guest can still view the destroy route.

class SessionsController extends Controller
{
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'destroy']); // Guests can view every route except destroy. 
    }

The 'guest' middleware aka 'RedirectIfAuthenticated' is not to protect guest from some routes. As the class name tells you it is to redirect users away from this route if they are Authenticated you can also call them guest only . A good example is the login or register page. If you are already online than this page makes no sense.

If you want to protect a route from guest user use the 'auth' middleware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM