问题
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