Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ClientFactory.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Database\Factories\Common;
  3. use App\Models\Common\Address;
  4. use App\Models\Common\Client;
  5. use App\Models\Common\Contact;
  6. use App\Models\Company;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Client>
  10. */
  11. class ClientFactory extends Factory
  12. {
  13. /**
  14. * The name of the factory's corresponding model.
  15. */
  16. protected $model = Client::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. 'name' => $this->faker->company,
  27. 'currency_code' => fn (array $attributes) => Company::find($attributes['company_id'])->default->currency_code ?? 'USD',
  28. 'account_number' => $this->faker->unique()->numerify(str_repeat('#', 12)),
  29. 'website' => $this->faker->url,
  30. 'notes' => $this->faker->sentence,
  31. 'created_by' => 1,
  32. 'updated_by' => 1,
  33. ];
  34. }
  35. public function withContacts(int $count = 1): self
  36. {
  37. return $this->has(
  38. Contact::factory()
  39. ->count($count)
  40. ->useParentCompany()
  41. );
  42. }
  43. public function withPrimaryContact(): self
  44. {
  45. return $this->has(
  46. Contact::factory()
  47. ->primary()
  48. ->useParentCompany()
  49. );
  50. }
  51. public function withAddresses(): self
  52. {
  53. return $this
  54. ->has(Address::factory()->billing()->useParentCompany())
  55. ->has(Address::factory()->shipping()->useParentCompany());
  56. }
  57. }