Bird
0
0

You run this Tinker command to create a new user:

medium📝 Debug Q14 of 15
Laravel - Database Basics and Migrations
You run this Tinker command to create a new user:
App\Models\User::create(['name' => 'Anna']);
But you get an error about mass assignment. What is the likely cause?
AThe database connection is missing
BYou forgot to run migrations
CThe 'create' method does not exist
DThe 'name' field is not fillable in the User model
Step-by-Step Solution
Solution:
  1. Step 1: Understand mass assignment protection

    Laravel requires you to specify which fields can be filled using 'fillable' property in the model.
  2. Step 2: Identify cause of error

    If 'name' is not listed in 'fillable', Laravel blocks mass assignment and throws an error.
  3. Final Answer:

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

    Mass assignment error = missing fillable field [OK]
Quick Trick: Add fields to $fillable to fix mass assignment errors [OK]
Common Mistakes:
  • Assuming database connection is the problem
  • Thinking 'create' method is missing
  • Ignoring fillable property in model

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes