| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace Database\Factories;
- use App\Models\Dictionary\Area;
- use App\Models\Dictionary\District;
- use App\Models\Order;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<Order>
- */
- class OrderFactory extends Factory
- {
- protected $model = Order::class;
- public function definition(): array
- {
- return [
- 'year' => (int) date('Y'),
- 'name' => fake()->bothify('Заказ-####'),
- 'user_id' => User::factory(),
- 'district_id' => District::factory(),
- 'area_id' => Area::factory(),
- 'object_address' => fake()->address(),
- 'object_type_id' => null,
- 'comment' => fake()->optional()->sentence(),
- 'installation_date' => fake()->optional()->dateTimeBetween('now', '+3 months')?->format('Y-m-d'),
- 'ready_date' => fake()->optional()->dateTimeBetween('-1 month', 'now')?->format('Y-m-d'),
- 'brigadier_id' => null,
- 'order_status_id' => Order::STATUS_NEW,
- 'tg_group_name' => null,
- 'tg_group_link' => null,
- 'ready_to_mount' => 'Нет',
- 'install_days' => fake()->numberBetween(1, 14),
- ];
- }
- public function withStatus(int $status): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_status_id' => $status,
- ]);
- }
- public function readyToMount(): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_status_id' => Order::STATUS_READY_TO_MOUNT,
- 'ready_to_mount' => 'Да',
- ]);
- }
- public function inMount(): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_status_id' => Order::STATUS_IN_MOUNT,
- ]);
- }
- public function handedOver(): static
- {
- return $this->state(fn (array $attributes) => [
- 'order_status_id' => Order::STATUS_HANDED_OVER,
- ]);
- }
- public function withBrigadier(User $brigadier = null): static
- {
- return $this->state(fn (array $attributes) => [
- 'brigadier_id' => $brigadier?->id ?? User::factory(),
- ]);
- }
- }
|