I'm attempting to set cookies on Laravel Octane, however the cookies appear to be not defined on the given index.
setcookie(self::JWT_TOKEN_COOKIE, $token_details['access_token'], [
'httponly' => true,
'expires' => time() + $token_details['expires_in'],
'path' => '/'
]);
die($_COOKIE[self::JWT_TOKEN_COOKIE]);
When attempting to print the Cookie, I get an error telling me it hasnt been set.
Undefined array key "JWT_TOKEN"
Is there something wrong in the way I'm setting cookies in Laravel Octane? Is there a new class I should be using to use these as the application is now fully held in RAM/loaded once?
The
setcookie
function add theSet-Cookie
headerSuperglobal array
$_COOKIE
reads from theCookie
headerRemove the
die
function and reload the page, cookie will appearExample
Request to the script with saving cookies to tmp file
Request to the script with saved cookies
Use laravel response object to send the cookie
https://laravel.com/docs/9.x/responses#attaching-cookies-to-responses