# How to update a request CookieCollection after removing a cookie object

**URL:** <https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509>\
**Category:** Need Help\
**Tags:** behavior\
**Created:** [January 10, 2019, 7:17am UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509 "2019-01-10T07:17:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hopeson](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Hopeson](https://discourse.cakephp.org/u/Hopeson)\
**Post date:** [January 10, 2019, 7:17am UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509/1 "2019-01-10T07:17:27Z")

</div>

Hello everyone, I am having problems working with request cookies on my project. I have a cookie collection with about 3 values a, b, and c.  
Then I try the following for instance:  
`$cookieCollection = $this->getRequest()->getCookieCollection();`  
`if ($cookieCollection->has('b')) {`  
`$cookieCollection->remove('b');`  
`}`  
After doing this the ‘b’ is removed only from this instance:  
`$cookieCollection`.  
But it is still there in `$this->getRequest()->getCookieCollection();`  
Now how do I update the `CookieCollection` so that ‘b’ will no longer exist anywhere in the entire site?

---

<div class="post-metadata">

**Author:** ![ADmad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/admad/32/20_2.png) [@ADmad](https://discourse.cakephp.org/u/ADmad)\
**Post date:** [January 12, 2019, 6:14am UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509/2 "2019-01-12T06:14:05Z")

</div>

`$this->request = $this->request->withCookieCollection($cookieCollection);`

---

<div class="post-metadata">

**Author:** ![Hopeson](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Hopeson](https://discourse.cakephp.org/u/Hopeson)\
**Post date:** [January 12, 2019, 10:11am UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509/3 "2019-01-12T10:11:07Z")

</div>

Thanks ADmad, for your response. But I have tried that, and it’s not working.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 12, 2019, 6:39pm UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509/4 "2019-01-12T18:39:26Z")

</div>

Both the request and the cookie collection are immutable objects, so in addition to what @ADmad said, you also need

`$cookieCollection = $cookieCollection->remove('b');`

---

<div class="post-metadata">

**Author:** ![kadamsuniljob](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@kadamsuniljob](https://discourse.cakephp.org/u/kadamsuniljob)\
**Post date:** [March 12, 2020, 7:24am UTC](https://discourse.cakephp.org/t/how-to-update-a-request-cookiecollection-after-removing-a-cookie-object/5509/5 "2020-03-12T07:24:42Z")

</div>

I Have also same issue not able to update cookie  
$cookieCollection=$this-\>getRequest()-\>getCookieCollection();  
$cookieCollection1 = $cookieCollection-\>remove(‘remember\_me’);  
$this-\>request = $this-\>request-\>withCookieCollection($cookieCollection1);
