Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

VendorFactory.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Database\Factories\Common;
  3. use App\Enums\Common\ContractorType;
  4. use App\Enums\Common\VendorType;
  5. use App\Models\Common\Address;
  6. use App\Models\Common\Contact;
  7. use App\Models\Common\Vendor;
  8. use Illuminate\Database\Eloquent\Factories\Factory;
  9. /**
  10. * @extends Factory<Vendor>
  11. */
  12. class VendorFactory extends Factory
  13. {
  14. /**
  15. * The name of the factory's corresponding model.
  16. */
  17. protected $model = Vendor::class;
  18. /**
  19. * Define the model's default state.
  20. *
  21. * @return array<string, mixed>
  22. */
  23. public function definition(): array
  24. {
  25. return [
  26. 'company_id' => 1,
  27. 'name' => $this->faker->company,
  28. 'type' => $this->faker->randomElement(VendorType::cases()),
  29. 'contractor_type' => function (array $attributes) {
  30. return $attributes['type'] === VendorType::Contractor ? $this->faker->randomElement(ContractorType::cases()) : null;
  31. },
  32. 'ssn' => function (array $attributes) {
  33. return $attributes['contractor_type'] === ContractorType::Individual ? $this->faker->numerify(str_repeat('#', 9)) : null;
  34. },
  35. 'ein' => function (array $attributes) {
  36. return $attributes['contractor_type'] === ContractorType::Business ? $this->faker->numerify(str_repeat('#', 9)) : null;
  37. },
  38. 'currency_code' => 'USD',
  39. 'account_number' => $this->faker->unique()->numerify(str_repeat('#', 12)),
  40. 'website' => $this->faker->url,
  41. 'notes' => $this->faker->sentence,
  42. 'created_by' => 1,
  43. 'updated_by' => 1,
  44. ];
  45. }
  46. public function regular(): self
  47. {
  48. return $this->state([
  49. 'type' => VendorType::Regular,
  50. ]);
  51. }
  52. public function contractor(): self
  53. {
  54. return $this->state([
  55. 'type' => VendorType::Contractor,
  56. ]);
  57. }
  58. public function individualContractor(): self
  59. {
  60. return $this->state([
  61. 'type' => VendorType::Contractor,
  62. 'contractor_type' => ContractorType::Individual,
  63. ]);
  64. }
  65. public function businessContractor(): self
  66. {
  67. return $this->state([
  68. 'type' => VendorType::Contractor,
  69. 'contractor_type' => ContractorType::Business,
  70. ]);
  71. }
  72. public function withContact(): self
  73. {
  74. return $this->has(Contact::factory()->primary());
  75. }
  76. public function withAddress(): self
  77. {
  78. return $this->has(Address::factory()->general());
  79. }
  80. }