Bird
0
0

What will happen if you call Post::factory()->create(['title' => 'Custom Title']) given a factory that defines a default title?

medium📝 Predict Output Q5 of 15
Laravel - Database Basics and Migrations
What will happen if you call Post::factory()->create(['title' => 'Custom Title']) given a factory that defines a default title?
ACreates and saves a Post with title 'Custom Title', overriding default
BThrows an error because title is defined twice
CCreates a Post with default title ignoring the passed value
DCreates a Post but title remains null
Step-by-Step Solution
Solution:
  1. Step 1: Understand attribute overriding in factory create()

    Attributes passed to create() override factory defaults.
  2. Step 2: Confirm the result of overriding

    The saved model will have the passed title value.
  3. Final Answer:

    Creates and saves a Post with title 'Custom Title', overriding default -> Option A
  4. Quick Check:

    Passed attributes override defaults = A [OK]
Quick Trick: Attributes passed to create() override factory defaults [OK]
Common Mistakes:
  • Thinking it causes errors
  • Assuming defaults always apply
  • Expecting null values instead

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes