0
0
Laravelframework~10 mins

Cookie handling in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a cookie named 'user' with value 'John' that lasts 60 minutes.

Laravel
return response('Hello World')->cookie('user', [1], 60);
Drag options to blanks, or click blank then click option'
A60
B'user'
C'John'
D'Hello World'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the cookie name instead of the value.
Confusing the duration with the value.
2fill in blank
medium

Complete the code to retrieve the value of the cookie named 'user' from the request.

Laravel
$user = $request->cookie([1]);
Drag options to blanks, or click blank then click option'
A'value'
B'user'
C'request'
D'cookie'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the cookie value instead of the name.
Using incorrect method names.
3fill in blank
hard

Fix the error in the code to delete the cookie named 'user'.

Laravel
return response('Goodbye')->[1]('user');
Drag options to blanks, or click blank then click option'
AdeleteCookie
BforgetCookie
Ccookie
Dforget
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'deleteCookie' or 'forgetCookie'.
Using the 'cookie' method which sets a cookie instead of deleting.
4fill in blank
hard

Fill both blanks to create a cookie named 'session' with value 'abc123' that lasts 120 minutes and is HTTP only.

Laravel
return response('Session set')->cookie([1], [2], 120, null, null, false, true);
Drag options to blanks, or click blank then click option'
A'session'
B'abc123'
C'user'
D'token'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping name and value.
Using wrong cookie names.
5fill in blank
hard

Fill all three blanks to set a cookie named 'theme' with value 'dark', lasting 30 minutes, and accessible only via HTTPS.

Laravel
return response('Theme set')->cookie([1], [2], [3], null, null, true);
Drag options to blanks, or click blank then click option'
A'theme'
B'dark'
C30
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong duration values.
Forgetting to set HTTPS only flag.