Uploading multiple images and post-processing

Hi heroes, am having trouble getting this upload to save correctly - I have a form that allows for multiple file uploads (images) for a photo gallery. I've figured out how to handle the post-processing step with the afterStateUpdated() method, but when enumerating the files collection I'm having trouble resolving the filenames. heres' my snippet, can anyone provide some insight as to where I'm going wrong? I am new to filament, and want to use the same string for the filesystem filename and the "filename" field in my record. I think I am getting differing values due to teh livewire lifecycle and can't seem to get it straight. Any help is greatly appreciated
->afterStateUpdated(function ($state, $set, $record) {
// This function will be called after files are uploaded
foreach ($state as $file) {
$originalFilename = $file->getClientOriginalName(); // Get the original filename
$savedFilename = $file->hashName(); // get the saved filename with extension
$filename = pathinfo($savedFilename, PATHINFO_BASENAME);

// Create a new Photo record for each uploaded file
Photo::create([
'gallery_id' => $record->id,
'filename' => $filename,
'name' => $originalFilename
]);
}
})->columnSpan("full"),
->afterStateUpdated(function ($state, $set, $record) {
// This function will be called after files are uploaded
foreach ($state as $file) {
$originalFilename = $file->getClientOriginalName(); // Get the original filename
$savedFilename = $file->hashName(); // get the saved filename with extension
$filename = pathinfo($savedFilename, PATHINFO_BASENAME);

// Create a new Photo record for each uploaded file
Photo::create([
'gallery_id' => $record->id,
'filename' => $filename,
'name' => $originalFilename
]);
}
})->columnSpan("full"),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server