Reputation: 549
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...
Upvotes: 4
Views: 5426
Reputation: 574
Try redirecting like this:
return redirect('/')->withCookie(Cookie::forget('cavpad'))->withCookie(Cookie::forget('cavuser'));
Upvotes: 1
Reputation: 1276
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.
Upvotes: 1