Complete the code to set a cookie named 'user' with value 'John' that lasts 60 minutes.
return response('Hello World')->cookie('user', [1], 60);
The cookie method takes the cookie name, value, and duration in minutes. Here, the value should be 'John'.
Complete the code to retrieve the value of the cookie named 'user' from the request.
$user = $request->cookie([1]);The cookie method on the request object takes the cookie name as argument to get its value.
Fix the error in the code to delete the cookie named 'user'.
return response('Goodbye')->[1]('user');
To delete a cookie in Laravel, use the forget method on the response object with the cookie name.
Fill both blanks to create a cookie named 'session' with value 'abc123' that lasts 120 minutes and is HTTP only.
return response('Session set')->cookie([1], [2], 120, null, null, false, true);
The first argument is the cookie name 'session', the second is its value 'abc123'. The last argument true makes it HTTP only.
Fill all three blanks to set a cookie named 'theme' with value 'dark', lasting 30 minutes, and accessible only via HTTPS.
return response('Theme set')->cookie([1], [2], [3], null, null, true);
The cookie name is 'theme', value is 'dark', duration is 30 minutes, and the last argument true makes it HTTPS only.