Bird
0
0

Which of the following is the correct syntax to create a cookie with name 'theme' and value 'dark' that lasts 60 minutes in Laravel?

easy📝 Syntax Q3 of 15
Laravel - Request and Response
Which of the following is the correct syntax to create a cookie with name 'theme' and value 'dark' that lasts 60 minutes in Laravel?
ACookie::queue('theme', 'dark', 60)
BCookie::make('theme', 'dark', 60)
Cresponse()->cookie('theme', 'dark', 60)
Dcookie('theme', 'dark', 60)
Step-by-Step Solution
Solution:
  1. Step 1: Identify the cookie creation syntax

    The response()->cookie() method is used to create and attach a cookie to the response with name, value, and duration in minutes.
  2. Step 2: Check other options

    Cookie::make() does not exist, Cookie::queue() queues cookie for response but does not create instance, cookie() helper creates a cookie instance but does not send it.
  3. Final Answer:

    response()->cookie('theme', 'dark', 60) -> Option C
  4. Quick Check:

    Create and attach cookie syntax = response()->cookie('name', 'value', minutes) [OK]
Quick Trick: Use response()->cookie('name', 'value', minutes) to create and send cookie [OK]
Common Mistakes:
  • Using Cookie::make() which does not exist
  • Confusing queue() with creation
  • Using cookie() helper alone does not send cookie

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes