Bird
0
0

You want to update the email of the user with ID 5 using Tinker. Which command correctly does this?

hard📝 Application Q15 of 15
Laravel - Database Basics and Migrations
You want to update the email of the user with ID 5 using Tinker. Which command correctly does this?
AApp\Models\User::update(['email' => 'new@example.com'])->where('id', 5);
BApp\Models\User::where('id', 5)->email = 'new@example.com';
CApp\Models\User::find(5)->update(['email' => 'new@example.com']);
DApp\Models\User::edit(5, ['email' => 'new@example.com']);
Step-by-Step Solution
Solution:
  1. Step 1: Find the user by ID

    Use find(5) to get the user model instance with ID 5.
  2. Step 2: Call update() on the model instance

    Use update() with an array of fields to change the email.
  3. Final Answer:

    App\Models\User::find(5)->update(['email' => 'new@example.com']); -> Option C
  4. Quick Check:

    Find then update = correct update method [OK]
Quick Trick: Use find(id)->update([...]) to update a record in Tinker [OK]
Common Mistakes:
  • Trying to update without finding the model first
  • Using non-existent methods like edit()
  • Calling update() before where()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes