ImportFactory.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\Import;
  4. use App\Models\User;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. /**
  7. * @extends Factory<Import>
  8. */
  9. class ImportFactory extends Factory
  10. {
  11. protected $model = Import::class;
  12. public function definition(): array
  13. {
  14. return [
  15. 'type' => fake()->randomElement(['orders', 'mafs', 'reclamations', 'catalog']),
  16. 'year' => (int) date('Y'),
  17. 'filename' => fake()->uuid() . '.xlsx',
  18. 'status' => Import::STATUS_PENDING,
  19. 'result' => '',
  20. 'user_id' => User::factory(),
  21. 'file_path' => null,
  22. 'original_filename' => fake()->word() . '.xlsx',
  23. ];
  24. }
  25. public function pending(): static
  26. {
  27. return $this->state(fn (array $attributes) => [
  28. 'status' => Import::STATUS_PENDING,
  29. ]);
  30. }
  31. public function completed(): static
  32. {
  33. return $this->state(fn (array $attributes) => [
  34. 'status' => Import::STATUS_COMPLETED,
  35. ]);
  36. }
  37. public function failed(): static
  38. {
  39. return $this->state(fn (array $attributes) => [
  40. 'status' => Import::STATUS_FAILED,
  41. ]);
  42. }
  43. public function orders(): static
  44. {
  45. return $this->state(fn (array $attributes) => [
  46. 'type' => 'orders',
  47. ]);
  48. }
  49. public function mafs(): static
  50. {
  51. return $this->state(fn (array $attributes) => [
  52. 'type' => 'mafs',
  53. ]);
  54. }
  55. public function reclamations(): static
  56. {
  57. return $this->state(fn (array $attributes) => [
  58. 'type' => 'reclamations',
  59. ]);
  60. }
  61. }