Bird
0
0

Which of the following is the correct syntax to define a factory for a Post model in Laravel?

easy📝 Syntax Q3 of 15
Laravel - Database Basics and Migrations
Which of the following is the correct syntax to define a factory for a Post model in Laravel?
Aclass PostFactory extends Seeder { public function definition() { return ['title' => fake()->sentence()]; } }
Bclass PostFactory { public function definition() { return ['title' => fake()->sentence()]; } }
Cclass PostFactory extends Factory { public function definition() { return ['title' => fake()->sentence()]; } }
Dclass PostFactory extends Model { public function definition() { return ['title' => fake()->sentence()]; } }
Step-by-Step Solution
Solution:
  1. Step 1: Check the class inheritance for factory

    Factory classes must extend Factory base class.
  2. Step 2: Verify method and return structure

    The definition() method returns an array with fake data.
  3. Final Answer:

    Class extends Factory with definition() returning attribute array -> Option C
  4. Quick Check:

    Factory class syntax = A [OK]
Quick Trick: Factory classes must extend Factory base class [OK]
Common Mistakes:
  • Not extending Factory base class
  • Extending Seeder or Model instead
  • Missing return array in definition()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes