create()->each(function ($brand) { Service::factory(1)->make()->each( /** @var \App\Models\Service $service*/ function ($service) use ($brand) { Question::factory(10)->make()->each(function ($question) use ($brand) { $question->brand()->associate($brand); $question->save(); Answer::factory(rand(3, 4))->make()->each(function ($answer) use ($question) { $answer->question()->associate($question); $answer->save(); }); }); $service->brand()->associate($brand); $service->save(); } ); }); } }