Nicolas
Nicolas

Reputation: 4756

How can I create and read a cookie in laravel 5.2

I'm trying to create and read a simple cookie in laravel but I don't understand how I can do this.

I've looked at the documentation of laravel, which normally is really solid but the cookie part confuses me.

https://laravel.com/docs/5.2/requests#cookies

I don't see the code for create a cookie and it seems like the plain setcookie() isn't working.

Thanks for the help

Upvotes: 0

Views: 1555

Answers (1)

z3r0ck
z3r0ck

Reputation: 683

Like everything else in laravel there are several ways of setting/getting cookies.

I do this (on my controller method) so the cookie will automatically be added to the outgoing response.

Cookie::queue($name, $value, $minutes);

In order to get the cookie you can use the

request()->cookie($name);

Upvotes: 1

Related Questions