88 lines
2.4 KiB
PHP
88 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\MediaDiskEnum;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Medium>
|
|
*/
|
|
class MediumFactory extends Factory
|
|
{
|
|
|
|
public function definition(): array
|
|
{
|
|
$filename = fake()->word() . '.' . fake()->fileExtension();
|
|
$disk = fake()->randomElement(MediaDiskEnum::cases());
|
|
$path = 'uploads/' . fake()->date('Y/m/d') . '/' . $filename;
|
|
|
|
return [
|
|
'filename' => $filename,
|
|
'disk' => $disk,
|
|
'path' => $path,
|
|
'size' => fake()->numberBetween(1024, 10485760),
|
|
'url' => fake()->optional()->url(),
|
|
'mime_type' => fake()->mimeType(),
|
|
];
|
|
}
|
|
|
|
|
|
public function public(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'disk' => MediaDiskEnum::Public,
|
|
'url' => null,
|
|
]);
|
|
}
|
|
|
|
|
|
public function private(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'disk' => MediaDiskEnum::Private,
|
|
'url' => null,
|
|
]);
|
|
}
|
|
|
|
public function image(): static
|
|
{
|
|
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
|
$extension = fake()->randomElement($imageExtensions);
|
|
$filename = fake()->word() . '.' . $extension;
|
|
|
|
return $this->state(fn (array $attributes) => [
|
|
'filename' => $filename,
|
|
'mime_type' => 'image/' . $extension,
|
|
'size' => fake()->numberBetween(102400, 5242880),
|
|
]);
|
|
}
|
|
|
|
public function document(): static
|
|
{
|
|
$docExtensions = ['pdf', 'doc', 'docx', 'txt'];
|
|
$extension = fake()->randomElement($docExtensions);
|
|
$filename = fake()->word() . '.' . $extension;
|
|
|
|
return $this->state(fn (array $attributes) => [
|
|
'filename' => $filename,
|
|
'mime_type' => $extension === 'pdf' ? 'application/pdf' : 'application/msword',
|
|
'size' => fake()->numberBetween(51200, 10485760),
|
|
]);
|
|
}
|
|
|
|
public function small(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'size' => fake()->numberBetween(1024, 102400),
|
|
]);
|
|
}
|
|
|
|
public function large(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'size' => fake()->numberBetween(5242880, 52428800),
|
|
]);
|
|
}
|
|
}
|