ReclamationFactory.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 'factory_reclamation_number' => fake()->optional()->bothify('FR-#####'),
  29. ];
  30. }
  31. public function withStatus(int $status): static
  32. {
  33. return $this->state(fn (array $attributes) => [
  34. 'status_id' => $status,
  35. ]);
  36. }
  37. public function inWork(): static
  38. {
  39. return $this->state(fn (array $attributes) => [
  40. 'status_id' => Reclamation::STATUS_IN_WORK,
  41. 'start_work_date' => now()->format('Y-m-d'),
  42. ]);
  43. }
  44. public function done(): static
  45. {
  46. return $this->state(fn (array $attributes) => [
  47. 'status_id' => Reclamation::STATUS_DONE,
  48. 'finish_date' => now()->format('Y-m-d'),
  49. ]);
  50. }
  51. public function forOrder(Order $order): static
  52. {
  53. return $this->state(fn (array $attributes) => [
  54. 'order_id' => $order->id,
  55. ]);
  56. }
  57. }