Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: How to set multiple cookie with one response?

I used to the to send response with a cookie by this way:

return $response->withCookie(cookie()->forever('region', $region));

It works perfectly. But now I want to send a response with multiple cookies set, could anyone please give me some suggestion about that?

like image 275
Sayakiss Avatar asked Dec 02 '22 11:12

Sayakiss


2 Answers

return $response
    ->withCookie(cookie()->forever('region', $region))
    ->withCookie(cookie()->forever('somethingElse', $somethingElse));
like image 124
Jono20201 Avatar answered Dec 06 '22 00:12

Jono20201


You can use Cookie queues to queue them, so that they will be automatically attached to the response when it is ready.

Cookie::queue(Cookie::forever('region', $region));
Cookie::queue(Cookie::forever('region2', $region2));
like image 23
ayip Avatar answered Dec 06 '22 00:12

ayip