Hint: Use Cookie::queue(Cookie::forget()) to delete cookies [OK]
Common Mistakes:
Trying to delete cookie without queue
Passing array instead of string cookie name
Thinking Cookie::forget() alone deletes cookie
5. You want to set a cookie named theme with value dark that expires in 60 minutes and then immediately retrieve it in the same request. Which approach correctly handles this in Laravel?
hard
A. Set the cookie with Cookie::queue() and store the value in a variable to use immediately
B. Use Cookie::set('theme', 'dark', 60) and then Cookie::get('theme')
C. Use Cookie::queue('theme', 'dark', 60) and then Cookie::get('theme') immediately
D. Set cookie in response headers manually and read from Cookie::get()
Solution
Step 1: Understand cookie availability timing
Cookies set with Cookie::queue() are sent with the response and not available in the current request.
Step 2: Use a variable to hold the value for immediate use
To use the cookie value immediately, store it in a variable before queuing the cookie.
Final Answer:
Set the cookie with Cookie::queue() and store the value in a variable to use immediately -> Option A
Quick Check:
Immediate use = store value before Cookie::queue() [OK]
Hint: Store value in variable before queuing cookie for immediate use [OK]
Common Mistakes:
Expecting Cookie::get() to return queued cookie immediately
Using non-existent Cookie::set() method
Trying to read cookie before response sent
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.