简体   繁体   English

Laravel保护路线不起作用

[英]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. “来宾”中间件(也称为“ RedirectIfAuthenticated” )并不是要保护来宾免受某些路由的侵害。 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. 如果您想保护来自来宾用户的路由,请使用“身份验证”中间件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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