Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unset cookie Laravel 4

How can I delete or destroy cookie in Laravel 4?

I have created it using the next code:

return Response::make('', 302, array('Location' => $_SERVER['HTTP_REFERER']))->withCookie($cookie);

But in the end, I need to destroy this data.

How can I do this?

like image 507
Vuk Stanković Avatar asked Jun 19 '13 20:06

Vuk Stanković


3 Answers

You have to use Cookie::forget like this:

$cookie = Cookie::forget('cookieKey');

return Response::make('foo')->withCookie($cookie);

remember you have to always return the cookie with the response, it's not like Session.

like image 183
Amir Avatar answered Nov 14 '22 09:11

Amir


Im pretty sure its the forget() method..

So in your case....when $cookie was made it was given a name, just unset it like so

Cookie::forget('yourCookie');
like image 2
Kylie Avatar answered Nov 14 '22 07:11

Kylie


here is a list of frequently used with cookie here is a list of frequently used with cookies .
u could check the detail on Laravel Api document . [2]http://laravel.com/api/class-Illuminate.Cookie.CookieJar.html
wish u good luck !

like image 1
Adams.H Avatar answered Nov 14 '22 08:11

Adams.H