Laravel cookie: Difference between revisions
From AWVVO
Jump to navigationJump to search
Tag: Reverted |
m →h4 Tag: Manual revert |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Set Cookie = | == Set Cookie == | ||
<syntaxhighlight lang="php" copy> | <syntaxhighlight lang="php" copy> | ||
Cookie::queue( | Cookie::queue( | ||
Line 91: | Line 91: | ||
</pre> | </pre> | ||
== Delete Cookie == | == Delete Cookie == |
Latest revision as of 05:39, 30 January 2025
Set Cookie
Cookie::queue(
'name', // 1. Cookie name
auth()->user()["name"], // 2. Cookie value
999999, // 3. Duration in minutes
'/', // 4. Path where cookie is available
null, // 5. Domain
false, // 6. Secure flag (HTTPS only)
false, // 7. HTTP only flag
false // 8. Raw flag
);
Parameter Details 1. Name Type: string Example: 'name' Purpose: Identifier for the cookie Required: Yes 2. Value Type: string|array Example: auth()->user()["name"] Purpose: Actual data to be stored in the cookie Required: Yes 3. Minutes Type: int Example: 999999 Purpose: Cookie lifetime in minutes Required: No (defaults to 0) Note: 0 creates a session cookie that expires when browser closes 4. Path Type: string Example: '/' Purpose: Server path where cookie is accessible Required: No (defaults to '/') Note: '/' makes cookie available across entire domain 5. Domain Type: string|null Example: null Purpose: Domain where cookie is valid Required: No (defaults to null) Note: Null uses current domain 6. Secure Type: boolean Example: false Purpose: Restricts cookie to HTTPS only Required: No (defaults to false) Values: true: HTTPS only false: Both HTTP and HTTPS 7. HttpOnly Type: boolean Example: false Purpose: Controls JavaScript access to cookie Required: No (defaults to true) Values: true: No JavaScript access false: JavaScript can access 8. Raw Type: boolean Example: false Purpose: Controls value encoding/decoding Required: No (defaults to false) Values: true: No encoding/decoding false: Automatically encode/decode value
Delete Cookie
Cookie::queue(Cookie::forget('name'));