How to dynamically name uploaded images based on the number of images.
Hello,
In my V2 project I'm trying to upload images by giving name dynamically based on the number of image. 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 Replies