Generate unique time() filenames for file uploads inside Repeater

Im trying to generate filenames based on the time() method using getUploadedFileNameForStorageUsing inside a repeater. The problem is that all files are generated using the same time value and are overriden by the last file. This is the component (i dont want to include the original file name):
Forms\Components\Repeater::make('tour_locations')
->schema([
FileUpload::make('image_path')
->disk('s3')
->directory('images')
->visibility('public')
->label('Image')
->image()
->maxSize(256)
->required()
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => time() . "." . $file->getClientOriginalExtension()
),
])
Forms\Components\Repeater::make('tour_locations')
->schema([
FileUpload::make('image_path')
->disk('s3')
->directory('images')
->visibility('public')
->label('Image')
->image()
->maxSize(256)
->required()
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => time() . "." . $file->getClientOriginalExtension()
),
])
Solution:
time() returns timestamp with seconds precision so its normal behavior because its execution time might be under 1s you should use now()->getTimestampMs() or if you want more precision now()->getPreciseTimestamp(6)...
Jump to solution
1 Reply
Solution
awsqed
awsqed13mo ago
time() returns timestamp with seconds precision so its normal behavior because its execution time might be under 1s you should use now()->getTimestampMs() or if you want more precision now()->getPreciseTimestamp(6)
Want results from more Discord servers?
Add your server