问题描述
我有此代码:
Cookie::forget('vendor');
return Redirect::route('vendor_login');
应该执行的操作是删除供应商cookie,然后将您重定向到登录页面.但是,它实际上并没有删除cookie.根据我的理解,我希望它为供应商发送一个setcookie标头,其值为null且时间为负.它根本不发送setcookie标头.为什么会这样?
What it is supposed to do, is remove the vendor cookie and redirect you to the login page. However, it doesn't actually delete the cookie. From my understanding, I would expect it to send a setcookie header for vendor with a value of null and a negative time. It doesn't send the setcookie header at all. Why is this?
这很完美:
Cookie::queue('paddle_vendor', null, -1);
return Redirect::route('vendor_login');
推荐答案
您可以使用queue
这样的方法:
You can use queue
method like this:
Cookie::queue(Cookie::forget('vendor'));
return Redirect::route('vendor_login');
通过这种方式,您也可以一次删除多个Cookie.有关更多信息,请在此处查看此答案: https://stackoverflow.com/a/33724308/247670
Which in this way it allows you to delete multiple cookies at once too.For more information checkout this answer here:https://stackoverflow.com/a/33724308/247670
或者像 Antonio 这样说:
$cookie = Cookie::forget('vendor');
return Redirect::route('vendor_login')->withCookie($cookie);
这篇关于Laravel cookie :: forget不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!