Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

webRookie's avatar

factory is not creating the right data

I tried to make one record of data that will have 3 children. The record is created but no children added. I don't see where is the problem. Maybe you can see.

public function setUp() { parent::setUp();

    if(!static::$quiz){

        static::$quiz = factory(Quiz::class, 1)
            ->create()
            ->each(function(Quiz $quiz){

                factory(\App\Question::class, 3)

                    ->create(['quiz_id'=> $quiz->id]);
            }
        );
    }
}
0 likes
1 reply
webRookie's avatar

I have found the problem. I think the if(!static::$quiz) is stopping the execution

Please or to participate in this conversation.