To add a cookie in Laravel, you can use the response
method to set the cookie on the client-side. Here's an example:
main.php133 chars4 lines
In this example, cookie('name', 'value', $minutes)
creates a cookie with a name of name
, a value of value
, and an expiration time of $minutes
minutes. You can then add this cookie to your response using the withCookie
method.
Alternatively, you can use the setcookie
function to create a cookie. Here's an example:
main.php56 chars2 lines
In this example, setcookie('name', 'value', $seconds, '/')
creates a cookie with a name of name
, a value of value
, an expiration time of $seconds
seconds (in this case, 30 days), and a path of '/'
(which means the cookie is available on the entire domain).
gistlibby LogSnag