Bird
0
0

Why does this seeder fail?

medium📝 Debug Q7 of 15
Laravel - Database Basics and Migrations
Why does this seeder fail?
public function run() {
    User::create(['name' => 'John']);
}

Assuming User model uses guarded property.
ABecause the create method does not exist on User model
BBecause the run method must use DB facade instead
CBecause the guarded property blocks mass assignment without fillable set
DBecause 'name' is not a valid column in users table
Step-by-Step Solution
Solution:
  1. Step 1: Understand Mass Assignment Protection

    If User model has guarded property set, mass assignment via create() is blocked unless fillable is defined.
  2. Step 2: Confirm Cause of Failure

    Without fillable or unguarded, create() throws a mass assignment exception causing seeder failure.
  3. Final Answer:

    Because the guarded property blocks mass assignment without fillable set -> Option C
  4. Quick Check:

    Guarded blocks create() without fillable [OK]
Quick Trick: Set fillable or unguarded for create() [OK]
Common Mistakes:
  • Assuming create() always works
  • Thinking run must use DB facade
  • Assuming column missing causes failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes