Skip to content

Commit a84d28c

Browse files
committed
Added a note about accessing cookies via a facade
1 parent 90117d3 commit a84d28c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

requests.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ All cookies created by the Laravel framework are encrypted and signed with an au
273273

274274
$value = $request->cookie('name');
275275

276+
Alternatively, you can use the `Cookie` facade:
277+
278+
Cookie::get('name');
279+
276280
#### Attaching Cookies To Responses
277281

278282
You may attach a cookie to an outgoing `Illuminate\Http\Response` instance using the `cookie` method. You should pass the name, value, and number of minutes the cookie should be considered valid to this method:
@@ -287,6 +291,14 @@ The `cookie` method also accepts a few more arguments which are used less freque
287291
'name', 'value', $minutes, $path, $domain, $secure, $httpOnly
288292
);
289293

294+
Alternatively, you can use the `Cookie` facade to queue cookies. The `queue` method accepts both a `Cookie` instance or a list of arguments to create one:
295+
296+
Cookie::queue(Cookie::make('name', 'value', $minutes));
297+
298+
Cookie::queue('name', 'value', $minutes);
299+
300+
These cookies will be attached to the response on its creation.
301+
290302
#### Generating Cookie Instances
291303

292304
If you would like to generate a `Symfony\Component\HttpFoundation\Cookie` instance that can be given to a response instance at a later time, you may use the global `cookie` helper. This cookie will not be sent back to the client unless it is attached to a response instance:

responses.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ The `cookie` method also accepts a few more arguments which are used less freque
7777

7878
->cookie($name, $value, $minutes, $path, $domain, $secure, $httpOnly)
7979

80+
Alternatively, you can use the `Cookie` facade to queue cookies. The `queue` method accepts both a `Cookie` instance or a list of arguments to create one:
81+
82+
Cookie::queue(Cookie::make('name', 'value', $minutes));
83+
84+
Cookie::queue('name', 'value', $minutes);
85+
86+
These cookies will be attached to the response on its creation.
87+
8088
<a name="cookies-and-encryption"></a>
8189
#### Cookies & Encryption
8290

0 commit comments

Comments
 (0)