Laravel cookie::forget doesn't work?

一个人想着一个人 提交于 2019-12-23 16:28:10

问题


I have this code:

Cookie::forget('vendor');
return Redirect::route('vendor_login');

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?

This works perfectly:

Cookie::queue('paddle_vendor', null, -1);
return Redirect::route('vendor_login');

回答1:


You can use queue method like this:

Cookie::queue(Cookie::forget('vendor'));
return Redirect::route('vendor_login');

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

Or do it like this as Antonio said:

$cookie = Cookie::forget('vendor');
return Redirect::route('vendor_login')->withCookie($cookie);



回答2:


You still need to send it with your response:

$cookie = Cookie::forget('vendor');

return Redirect::route('vendor_login')->withCookie($cookie);



回答3:


The default laravel

  Cookie::queue(
   Cookie::forget('name')
      ) ;

Should work perfectly fine if you have not done any changes on your session.php config file. Check it out and you should be good to go.



来源:https://stackoverflow.com/questions/23063240/laravel-cookieforget-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!