| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace Database\Factories;
- use App\Models\File;
- use App\Models\User;
- use Illuminate\Database\Eloquent\Factories\Factory;
- /**
- * @extends Factory<File>
- */
- class FileFactory extends Factory
- {
- protected $model = File::class;
- public function definition(): array
- {
- $filename = fake()->word() . '.' . fake()->randomElement(['jpg', 'png', 'pdf', 'xlsx']);
- return [
- 'user_id' => User::factory(),
- 'original_name' => $filename,
- 'mime_type' => fake()->mimeType(),
- 'path' => 'files/' . fake()->uuid() . '/' . $filename,
- 'link' => '/storage/files/' . fake()->uuid() . '/' . $filename,
- ];
- }
- public function image(): static
- {
- return $this->state(fn (array $attributes) => [
- 'original_name' => fake()->word() . '.jpg',
- 'mime_type' => 'image/jpeg',
- ]);
- }
- public function pdf(): static
- {
- return $this->state(fn (array $attributes) => [
- 'original_name' => fake()->word() . '.pdf',
- 'mime_type' => 'application/pdf',
- ]);
- }
- public function excel(): static
- {
- return $this->state(fn (array $attributes) => [
- 'original_name' => fake()->word() . '.xlsx',
- 'mime_type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- ]);
- }
- }
|