Bird
0
0

Consider this Laravel code:

medium📝 Predict Output Q5 of 15
Laravel - Request and Response
Consider this Laravel code:
$cookie = cookie('user', 'Bob', 10);
return response('Welcome')->cookie($cookie);

What will the browser receive?
AA response with body 'Welcome' but no cookie set
BAn error because cookie() cannot be passed to response()->cookie()
CA response with body 'Welcome' and a cookie 'user' set for 10 minutes
DA response with cookie 'user' but no body content
Step-by-Step Solution
Solution:
  1. Step 1: Create cookie instance

    cookie('user', 'Bob', 10) creates a cookie instance valid for 10 minutes.
  2. Step 2: Attach cookie to response

    response('Welcome')->cookie($cookie) attaches the cookie to the HTTP response with body 'Welcome'.
  3. Final Answer:

    A response with body 'Welcome' and a cookie 'user' set for 10 minutes -> Option C
  4. Quick Check:

    Attach cookie instance to response to set cookie [OK]
Quick Trick: Attach cookie instance to response() to send cookie [OK]
Common Mistakes:
  • Thinking cookie() cannot be passed to response()->cookie()
  • Expecting error due to wrong usage
  • Assuming no cookie is set without queue()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes