I'm trying to get Laravel 5.1 to delete my cookie, however it will not delete even though i'm returning it with my redirect.
return redirect('/voucher')->withCookie(Cookie::forget($cookie));
Have I done something wrong?
I'm trying to get Laravel 5.1 to delete my cookie, however it will not delete even though i'm returning it with my redirect.
return redirect('/voucher')->withCookie(Cookie::forget($cookie));
Have I done something wrong?
Maybe I am wrong, but you are probably using cookie object in place of cookie name when calling Cookie::forget($cookie)
. Unless $cookie
is a string containing cookie name, you should try something like this:
return redirect('/voucher')->withCookie(Cookie::forget('cookie_name'));
I know this is already an old and answered question but I got here recently and if I'm correct, the cookie needs to be 'queued' for the next response.
You can do that by adding the cookie manually to the response as @Jan.J already described in his answer. But if you need to do it inline, this might also work for you:
Cookie::queue(
Cookie::forget('cookieName')
);
The CookieJar
will pass all queued cookies to the next response.
In my case there was an array
stored in the cookie, so none of provided methods has worked. Array should be deleted providing exactly pair of array:
Cookie::queue(Cookie::forget('array_name[provide_key]'));
public function funname(CookieJar $cookie)
session()->flush();
$cookie->queue(cookie()->forget('user_email')); $cookie->queue(cookie()->forget('user_password'));
return redirect('/');
You can also do it this way:
redirect('/')->cookie(cookie()->forget('my_super_cookie_name))