Bird
0
0

Which of the following is the correct way to add the value 'green' to the session with the key 'background' in Laravel?

easy📝 Syntax Q3 of 15
Laravel - Request and Response
Which of the following is the correct way to add the value 'green' to the session with the key 'background' in Laravel?
Asession()->put('background', 'green');
Bsession()->add('background', 'green');
Csession()->store('background', 'green');
Dsession()->set('background', 'green');
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct method to store data in session

    Laravel uses the put() method to store key-value pairs in the session.
  2. Step 2: Check the syntax

    The syntax is session()->put('key', 'value');. session()->put('background', 'green'); matches this exactly.
  3. Final Answer:

    session()->put('background', 'green'); -> Option A
  4. Quick Check:

    Only put() is valid for storing session data [OK]
Quick Trick: Use session()->put('key', 'value') to store data [OK]
Common Mistakes:
  • Using non-existent methods like add(), store(), or set()
  • Confusing session()->put() with other session methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes