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.

AddressFactory.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Database\Factories\Common;
  3. use App\Enums\Common\AddressType;
  4. use App\Models\Common\Address;
  5. use Database\Factories\Concerns\HasParentRelationship;
  6. use Illuminate\Database\Eloquent\Factories\Factory;
  7. /**
  8. * @extends Factory<Address>
  9. */
  10. class AddressFactory extends Factory
  11. {
  12. use HasParentRelationship;
  13. /**
  14. * The name of the factory's corresponding model.
  15. */
  16. protected $model = Address::class;
  17. /**
  18. * Define the model's default state.
  19. *
  20. * @return array<string, mixed>
  21. */
  22. public function definition(): array
  23. {
  24. return [
  25. 'company_id' => 1,
  26. 'type' => $this->faker->randomElement(AddressType::cases()),
  27. 'recipient' => $this->faker->name,
  28. 'phone' => $this->faker->phoneNumber,
  29. 'address_line_1' => $this->faker->streetAddress,
  30. 'address_line_2' => $this->faker->streetAddress,
  31. 'city' => $this->faker->city,
  32. 'state_id' => $this->faker->state('US'),
  33. 'postal_code' => $this->faker->postcode,
  34. 'country_code' => 'US',
  35. 'notes' => $this->faker->sentence,
  36. 'created_by' => 1,
  37. 'updated_by' => 1,
  38. ];
  39. }
  40. public function billing(): self
  41. {
  42. return $this->state([
  43. 'type' => AddressType::Billing,
  44. ]);
  45. }
  46. public function shipping(): self
  47. {
  48. return $this->state([
  49. 'type' => AddressType::Shipping,
  50. ]);
  51. }
  52. public function general(): self
  53. {
  54. return $this->state([
  55. 'type' => AddressType::General,
  56. ]);
  57. }
  58. public function forCountry(string $countryCode): self
  59. {
  60. return $this->state([
  61. 'state_id' => $this->faker->state($countryCode),
  62. 'country_code' => $countryCode,
  63. ]);
  64. }
  65. }