*/ class CompanyProfileFactory extends Factory { /** * @var string The related model's name. */ protected $model = CompanyProfile::class; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'address' => $this->faker->streetAddress, 'zip_code' => $this->faker->postcode, 'country' => $this->faker->randomElement(CompanyProfile::getAvailableCountryCodes()), 'phone_number' => $this->faker->e164PhoneNumber, 'email' => $this->faker->email, 'entity_type' => $this->faker->randomElement(EntityType::class), 'fiscal_year_start' => (new \DateTime('first day of January'))->format('Y-m-d'), 'fiscal_year_end' => (new \DateTime('last day of December'))->format('Y-m-d'), ]; } public function configure(): static { return $this->afterCreating(function (CompanyProfile $companyProfile) { $companyProfile->timezone = $this->faker->randomElement(CompanyProfile::getTimezoneOptions($companyProfile->country)); $companyProfile->state = $this->faker->randomElement(CompanyProfile::getStateOptions($companyProfile->country)); $companyProfile->save(); event(new CompanyGenerated($companyProfile->company->owner, $companyProfile->company, $companyProfile->country)); }); } }