create()->each(function ($customer) use (&$hasSetAtLeasOneActivated) { /** @var \App\Models\Brand */ foreach (Brand::all() as $brand) { CustomerInfo::factory(1)->make()->each( function ($customerInfo) use ($customer, $brand) { $customerInfo->customer()->associate($customer); $customerInfo->brand()->associate($brand); $customerInfo->save(); } ); CustomerLogin::factory(1)->make()->each( function ($customerLogin) use ($customer, $brand, &$hasSetAtLeasOneActivated) { $customerLogin->customer()->associate($customer); $customerLogin->brand()->associate($brand); if (!$hasSetAtLeasOneActivated) { $hasSetAtLeasOneActivated = true; $customerLogin->status = true; } $customerLogin->save(); } ); } $answerModels = Answer::inRandomOrder()->take(rand(1, 3))->get()->modelKeys(); $customer->answers()->attach($answerModels); }); } }