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.

AccountFactory.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Banking\Account;
  4. use Illuminate\Database\Eloquent\Factories\Factory;
  5. /**
  6. * @extends Factory<Account>
  7. */
  8. class AccountFactory extends Factory
  9. {
  10. /**
  11. * The name of the factory's corresponding model.
  12. *
  13. * @var string
  14. */
  15. protected $model = Account::class;
  16. /**
  17. * Define the model's default state.
  18. *
  19. * @return array<string, mixed>
  20. */
  21. public function definition(): array
  22. {
  23. $types = ['bank', 'card'];
  24. return [
  25. 'type' => $this->faker->randomElement($types),
  26. 'name' => $this->faker->text(15),
  27. 'number' => (string) $this->faker->randomNumber(12, true),
  28. 'currency_code' => $this->company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
  29. 'opening_balance' => '0',
  30. 'bank_name' => $this->faker->text(15),
  31. 'bank_phone' => $this->faker->phoneNumber,
  32. 'bank_address' => $this->faker->address,
  33. 'enabled' => $this->faker->boolean,
  34. 'company_id' => $this->company->id,
  35. ];
  36. }
  37. /**
  38. * Indicate that the model is enabled.
  39. *
  40. * @return Factory<Account>
  41. */
  42. public function enabled(): Factory
  43. {
  44. return $this->state(function (array $attributes) {
  45. return [
  46. 'enabled' => true,
  47. ];
  48. });
  49. }
  50. /**
  51. * Indicate that the model is disabled.
  52. *
  53. * @return Factory<Account>
  54. */
  55. public function disabled(): Factory
  56. {
  57. return $this->state(function (array $attributes) {
  58. return [
  59. 'enabled' => false,
  60. ];
  61. });
  62. }
  63. /**
  64. * Indicate that the default currency is used.
  65. *
  66. * @return Factory<Account>
  67. */
  68. public function default_currency(): Factory
  69. {
  70. return $this->state(function (array $attributes) {
  71. return [
  72. 'currency_code' => $this->default_currency(),
  73. ];
  74. });
  75. }
  76. }