add a cookie in laravel in php

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.php
$response = new Illuminate\Http\Response('Hello World');
$response->withCookie(cookie('name', 'value', $minutes));
return $response;
133 chars
4 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.php
setcookie('name', 'value', time() + (86400 * 30), "/");
56 chars
2 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