選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CompanyProfileFactory.php 1.8KB

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