Sayalic
Sayalic

Reputation: 7650

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?

Upvotes: 6

Views: 7186

Answers (2)

ayip
ayip

Reputation: 2543

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));

Upvotes: 8

Jono20201
Jono20201

Reputation: 3205

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

Upvotes: 14

Related Questions