*/ class MediaFactory extends Factory { protected $model = Media::class; /** * @return array */ public function definition(): array { return [ 'disk' => (string) config('media.disk', 'public'), 'path' => 'projects/'.fake()->unique()->uuid().'.jpg', 'mime' => 'image/jpeg', 'size' => fake()->numberBetween(50_000, 900_000), 'width' => null, 'height' => null, 'variants' => null, 'placeholder' => null, 'processed_at' => null, ]; } /** * An image the processor has already been through. */ public function processed(int $width = 1600, int $height = 900): static { return $this->state(fn (array $attributes) => [ 'width' => $width, 'height' => $height, 'placeholder' => 'data:image/webp;base64,UklGRhoAAABXRUJQ', 'variants' => collect([400, 800, 1200]) ->filter(fn (int $w) => $w < $width) ->map(fn (int $w) => [ 'format' => 'webp', 'width' => $w, 'path' => str_replace('.jpg', "-{$w}.webp", $attributes['path']), 'size' => $w * 100, ]) ->values() ->all(), 'processed_at' => now(), ]); } }