取消设置 cookie Laravel 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17200933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unset cookie Laravel 4
提问by Vuk Stankovi?
How can I delete or destroy cookie in Laravel 4?
如何在 Laravel 4 中删除或销毁 cookie?
I have created it using the next code:
我使用下一个代码创建了它:
return Response::make('', 302, array('Location' => $_SERVER['HTTP_REFERER']))->withCookie($cookie);
return Response::make('', 302, array('Location' => $_SERVER['HTTP_REFERER']))->withCookie($cookie);
But in the end, I need to destroy this data.
但最终,我需要销毁这些数据。
How can I do this?
我怎样才能做到这一点?
回答by Amir
You have to use Cookie::forget like this:
你必须像这样使用 Cookie::forget:
$cookie = Cookie::forget('cookieKey');
return Response::make('foo')->withCookie($cookie);
remember you have to always return the cookie with the response, it's not like Session.
请记住,您必须始终将 cookie 与响应一起返回,这与 Session 不同。
回答by Kylie
Im pretty sure its the forget()
method..
我很确定它的forget()
方法..
So in your case....when $cookie was made it was given a name, just unset it like so
所以在你的情况下......当 $cookie 被赋予一个名字时,就像这样取消它
Cookie::forget('yourCookie');
回答by Adams.H
here is a list of frequently used with cookies .
u could check the detail on Laravel Api document . [2]http://laravel.com/api/class-Illuminate.Cookie.CookieJar.html
wish u good luck !
这是一个经常使用的 cookie 列表。
你可以查看 Laravel Api 文档的详细信息。[2] http://laravel.com/api/class-Illuminate.Cookie.CookieJar.html
祝你好运!