Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Syed1980's avatar

In Filament V2, how to dynamically name uploaded images based on the number of images.

In my Filament V2 project, I'm trying to upload images by giving names dynamically based on the number of images. I have tried like this

`FileUpload::make('images') ->directory(function ($get) { return 'craft-images/' . $get('cg_number'); }) ->preserveFilenames() ->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file, $get): string {

$imageCount = count($get('images')) + 1; $filename = "/img_{$imageCount}"; dd($filename); return (string) $filename; })->multiple()->enableReordering()`

but dd($filename); gives me this below result "/img_6"

I want to store something like this in the database ["\img_1", "\img_2", "\img_3", "\img_4", "\img_5", "\img_6",]

I would be thankful for any assistance.

0 likes
0 replies

Please or to participate in this conversation.