You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompanyProfileFactory.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Database\Factories\Setting;
  3. use App\Enums\EntityType;
  4. use App\Events\CompanyGenerated;
  5. use App\Models\Setting\CompanyProfile;
  6. use Illuminate\Database\Eloquent\Factories\Factory;
  7. /**
  8. * @extends Factory<CompanyProfile>
  9. */
  10. class CompanyProfileFactory extends Factory
  11. {
  12. /**
  13. * @var string The related model's name.
  14. */
  15. protected $model = CompanyProfile::class;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition(): array
  22. {
  23. return [
  24. 'address' => $this->faker->streetAddress,
  25. 'city' => $this->faker->city,
  26. 'zip_code' => $this->faker->postcode,
  27. 'country' => $this->faker->randomElement(CompanyProfile::getAvailableCountryCodes()),
  28. 'phone_number' => $this->faker->e164PhoneNumber,
  29. 'email' => $this->faker->email,
  30. 'entity_type' => $this->faker->randomElement(EntityType::class),
  31. 'fiscal_year_start' => (new \DateTime('first day of January'))->format('Y-m-d'),
  32. 'fiscal_year_end' => (new \DateTime('last day of December'))->format('Y-m-d'),
  33. ];
  34. }
  35. public function configure(): static
  36. {
  37. return $this->afterCreating(function (CompanyProfile $companyProfile) {
  38. $companyProfile->timezone = $this->faker->randomElement(CompanyProfile::getTimezoneOptions($companyProfile->country));
  39. $companyProfile->state = $this->faker->randomElement(CompanyProfile::getStateOptions($companyProfile->country));
  40. $companyProfile->save();
  41. event(new CompanyGenerated($companyProfile->company->owner, $companyProfile->company, $companyProfile->country));
  42. });
  43. }
  44. }