Bird
0
0

You try this in Tinker:

medium📝 Debug Q7 of 15
Laravel - Database Basics and Migrations
You try this in Tinker:
$user = new App\Models\User;
$user->name = 'John';
$user->save();
But it throws an error. What is a common cause?
AYou forgot to import the User model namespace
BYou must use create() instead of new and save()
CTinker does not support saving new models
DThe 'name' attribute is not fillable or guarded in the User model
Step-by-Step Solution
Solution:
  1. Step 1: Understand mass assignment protection

    Laravel models protect attributes via fillable or guarded properties to prevent unwanted mass assignment.
  2. Step 2: Check if 'name' is allowed to be set

    If 'name' is not in fillable, save() will fail with mass assignment error.
  3. Final Answer:

    The 'name' attribute is not fillable or guarded in the User model -> Option D
  4. Quick Check:

    Missing fillable attribute causes save() error [OK]
Quick Trick: Add attributes to fillable to allow save() [OK]
Common Mistakes:
  • Assuming create() is mandatory over new + save()
  • Thinking Tinker cannot save models
  • Forgetting to check fillable properties

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes