| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace Database\Factories;
- use App\Models\Dictionary\Area;
- use App\Models\Dictionary\District;
- use App\Models\ObjectType;
- 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' => ObjectType::factory(),
- '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(),
- ]);
- }
- }
|