Creating a new Cookie


You want to create a cookie.


Use Cookie::make()

You can use this method to generate a new cookie. Keep in mind, this does not send a cookie to the user, it simply creates a cookie object.

To create a simple cookie, which will expire at the end of the user’s session.

$cookie = Cookie::make($name, $value);

To create a cookie that won’t expire for 60 minutes, add a third parameters.

$cookie = Cookie::make($name, $value, 60);

Of course, you can pass all the normal cookie parameters.

$cookie = Cookie::make($name, $value, $minutes, $path, $domain,
                       $secure, $httpOnly);


What should you do with the cookie?

Well, normally, you’d send it the user. Additional recipes coming for this.

About the author