How to update a request CookieCollection after removing a cookie object



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')) {
After doing this the ‘b’ is removed only from this instance:
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?


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


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


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

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