问题
How do you a delete cookies in Laravel. This is not working:
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
Cookie::queue(Cookie::forget('cavpad'));
Cookie::queue(Cookie::forget('cavuser'));
return redirect('/');
}
This works, but seems the wrong way to do it:
Cookie::queue(Cookie::make('cavpad', '', 0, null, env('APP_DOMAIN')));
Cookie::queue(Cookie::make('cavuser', '', 0, null, env('APP_DOMAIN')));
Why does the first way not work, but the second way does... btw, has nothing to do with the env()... Just added that in there...
回答1:
You can do this by using the code I provided, it's pretty much the same, but I know that this way of doing it works for me. But if you need to do it inline, this might also work for you:
Cookie::queue(
Cookie::forget('cookieName')
);
This is how I think it should be done.
回答2:
Try redirecting like this:
return redirect('/')->withCookie(Cookie::forget('cavpad'))->withCookie(Cookie::forget('cavuser'));
来源:https://stackoverflow.com/questions/39840080/laravel-delete-forget-cookie-not-working