ReclamationFactory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Order;
  4. use App\Models\Reclamation;
  5. use App\Models\User;
  6. use Illuminate\Database\Eloquent\Factories\Factory;
  7. /**
  8. * @extends Factory<Reclamation>
  9. */
  10. class ReclamationFactory extends Factory
  11. {
  12. protected $model = Reclamation::class;
  13. public function definition(): array
  14. {
  15. return [
  16. 'order_id' => Order::factory(),
  17. 'user_id' => User::factory(),
  18. 'status_id' => Reclamation::STATUS_NEW,
  19. 'reason' => fake()->sentence(),
  20. 'guarantee' => fake()->boolean(),
  21. 'whats_done' => fake()->optional()->sentence(),
  22. 'create_date' => fake()->dateTimeBetween('-1 month', 'now')->format('Y-m-d'),
  23. 'finish_date' => fake()->dateTimeBetween('now', '+1 month')->format('Y-m-d'),
  24. 'start_work_date' => null,
  25. 'work_days' => fake()->numberBetween(1, 14),
  26. 'brigadier_id' => null,
  27. 'comment' => fake()->optional()->sentence(),
  28. ];
  29. }
  30. public function withStatus(int $status): static
  31. {
  32. return $this->state(fn (array $attributes) => [
  33. 'status_id' => $status,
  34. ]);
  35. }
  36. public function inWork(): static
  37. {
  38. return $this->state(fn (array $attributes) => [
  39. 'status_id' => Reclamation::STATUS_IN_WORK,
  40. 'start_work_date' => now()->format('Y-m-d'),
  41. ]);
  42. }
  43. public function done(): static
  44. {
  45. return $this->state(fn (array $attributes) => [
  46. 'status_id' => Reclamation::STATUS_DONE,
  47. 'finish_date' => now()->format('Y-m-d'),
  48. ]);
  49. }
  50. public function forOrder(Order $order): static
  51. {
  52. return $this->state(fn (array $attributes) => [
  53. 'order_id' => $order->id,
  54. ]);
  55. }
  56. }