OrderFactory.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Dictionary\Area;
  4. use App\Models\Dictionary\District;
  5. use App\Models\Order;
  6. use App\Models\User;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. /**
  9. * @extends Factory<Order>
  10. */
  11. class OrderFactory extends Factory
  12. {
  13. protected $model = Order::class;
  14. public function definition(): array
  15. {
  16. return [
  17. 'year' => (int) date('Y'),
  18. 'name' => fake()->bothify('Заказ-####'),
  19. 'user_id' => User::factory(),
  20. 'district_id' => District::factory(),
  21. 'area_id' => Area::factory(),
  22. 'object_address' => fake()->address(),
  23. 'object_type_id' => null,
  24. 'comment' => fake()->optional()->sentence(),
  25. 'installation_date' => fake()->optional()->dateTimeBetween('now', '+3 months')?->format('Y-m-d'),
  26. 'ready_date' => fake()->optional()->dateTimeBetween('-1 month', 'now')?->format('Y-m-d'),
  27. 'brigadier_id' => null,
  28. 'order_status_id' => Order::STATUS_NEW,
  29. 'tg_group_name' => null,
  30. 'tg_group_link' => null,
  31. 'ready_to_mount' => 'Нет',
  32. 'install_days' => fake()->numberBetween(1, 14),
  33. ];
  34. }
  35. public function withStatus(int $status): static
  36. {
  37. return $this->state(fn (array $attributes) => [
  38. 'order_status_id' => $status,
  39. ]);
  40. }
  41. public function readyToMount(): static
  42. {
  43. return $this->state(fn (array $attributes) => [
  44. 'order_status_id' => Order::STATUS_READY_TO_MOUNT,
  45. 'ready_to_mount' => 'Да',
  46. ]);
  47. }
  48. public function inMount(): static
  49. {
  50. return $this->state(fn (array $attributes) => [
  51. 'order_status_id' => Order::STATUS_IN_MOUNT,
  52. ]);
  53. }
  54. public function handedOver(): static
  55. {
  56. return $this->state(fn (array $attributes) => [
  57. 'order_status_id' => Order::STATUS_HANDED_OVER,
  58. ]);
  59. }
  60. public function withBrigadier(User $brigadier = null): static
  61. {
  62. return $this->state(fn (array $attributes) => [
  63. 'brigadier_id' => $brigadier?->id ?? User::factory(),
  64. ]);
  65. }
  66. }