make()->each(function ($brand) { $brand->logo = FileHelper::storeFile( $brand, new \SplFileInfo( \resource_path('../database/factories/assets/brands/default-logo-550x550.jpg') ) ); $brand->saveOrFail(); 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(); } ); }); } }