OrderFactory.php 2.2 KB

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