You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

11 months ago
<?php
namespace Database\Factories;
use App\Models\Upload;
use Illuminate\Database\Eloquent\Factories\Factory;
class UploadFactory extends Factory
{
protected $model = Upload::class;
public function definition()
{
$extension = $this->faker->randomElement(['jpg', 'png', 'pdf', 'doc', 'docx']);
$originalName = $this->faker->word . '.' . $extension;
$name = $this->faker->uuid . '.' . $extension;
return [
'belongs_type' => $this->faker->randomElement(['visit', 'study', 'blacklist']),
'belongs_id' => $this->faker->numberBetween(1, 100),
'original_name' => $originalName,
'folder' => 'uploads/' . $this->faker->date('Y/m/d'),
'name' => $name,
'extension' => $extension,
'size' => $this->faker->numberBetween(1024, 10485760), // 1KB to 10MB
'creator_type' => 'admin',
'creator_id' => $this->faker->numberBetween(1, 10),
];
}
public function image()
{
return $this->state(function (array $attributes) {
$extension = $this->faker->randomElement(['jpg', 'png', 'gif']);
$originalName = $this->faker->word . '.' . $extension;
$name = $this->faker->uuid . '.' . $extension;
return [
'original_name' => $originalName,
'name' => $name,
'extension' => $extension,
];
});
}
public function document()
{
return $this->state(function (array $attributes) {
$extension = $this->faker->randomElement(['pdf', 'doc', 'docx', 'xls', 'xlsx']);
$originalName = $this->faker->word . '.' . $extension;
$name = $this->faker->uuid . '.' . $extension;
return [
'original_name' => $originalName,
'name' => $name,
'extension' => $extension,
];
});
}
}