Support the ongoing development of Laravel.io →
posted 10 years ago
Session

( version 4.2.8 )

I noticed the cookie only go away when we use a response and withCookie.

But is it possible to forget more cookies at once ?

I tried an array, but it didn't let me:

return Response::make('nocookie')->withCookie( array( $foo, $bar ) );
Last updated 3 years ago.
0

Hmm... well, I know unsetting a cookie is achieved with the following:

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

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

but to do multiple, you could do this:

public function unsetCookies(Array $cookieList)
{
  if(!empty($cookieList)) {
    foreach($cookieList as $cookie) {
        $this->headers->setCookie($cookie);
        return $this;
    }
   }else {
        return Redirect::back()->with('Error', 'No cookies have been given for hunting and destroying!');
   }
}
Last updated 3 years ago.
0

In case anyone wanders in and wants to know, the answer is to make an array of the cookies and then use the withCookies method, which accepts an array as the parameter.

$cookie[0] = Cookie::forget('key1');
$cookie[1] = Cookie::forget('key2');

return Response::make('thisResponse')->withCookies($cookie); 

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.