FileFactory.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\File;
  4. use App\Models\User;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. /**
  7. * @extends Factory<File>
  8. */
  9. class FileFactory extends Factory
  10. {
  11. protected $model = File::class;
  12. public function definition(): array
  13. {
  14. $filename = fake()->word() . '.' . fake()->randomElement(['jpg', 'png', 'pdf', 'xlsx']);
  15. return [
  16. 'user_id' => User::factory(),
  17. 'original_name' => $filename,
  18. 'mime_type' => fake()->mimeType(),
  19. 'path' => 'files/' . fake()->uuid() . '/' . $filename,
  20. 'link' => '/storage/files/' . fake()->uuid() . '/' . $filename,
  21. ];
  22. }
  23. public function image(): static
  24. {
  25. return $this->state(fn (array $attributes) => [
  26. 'original_name' => fake()->word() . '.jpg',
  27. 'mime_type' => 'image/jpeg',
  28. ]);
  29. }
  30. public function pdf(): static
  31. {
  32. return $this->state(fn (array $attributes) => [
  33. 'original_name' => fake()->word() . '.pdf',
  34. 'mime_type' => 'application/pdf',
  35. ]);
  36. }
  37. public function excel(): static
  38. {
  39. return $this->state(fn (array $attributes) => [
  40. 'original_name' => fake()->word() . '.xlsx',
  41. 'mime_type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  42. ]);
  43. }
  44. }