Reputation: 51
I'm having an issue removing a cookie in laravel. I set the cookie at login as 'sessionToken' and once the user logs out I flush the session, update sessionToken column to null, and forget the cookie. Yet, I can still see the cookie when I use "document.cookie" in the browser console.
How can I destroy that cookie & its value? I feel like this isn't normal behavior but I could be wrong.
public function logout(Request $request, User $_id)
{
Auth::logout();
$user = User::where('id', $request->$_id)->first();
$user->sessionToken = null;
$user->save();
Session::flush();
Cookie::queue(Cookie::forget('sessionToken'));
return redirect()->route('cookie-login')->withCookie(Cookie::forget('sessionToken'));
}
Upvotes: 2
Views: 3511
Reputation: 715
You can also do this, this removed the cookie from the browser.
Cookie::queue(Cookie::forget('name'));
Upvotes: 2
Reputation: 51
After much digging, I found a work around to remove the cookie. Setting the value to an empty string totally removes the cookie from the browser window.
$cookieValue = '';
Cookie::queue(Cookie::make('cookie', $cookieValue))
Upvotes: 0