© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago
islandnuge

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"),
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Uploading images in Production
FilamentFFilament / ❓┊help
2y ago
Gallery with Multiple Images and multiple image upload
FilamentFFilament / ❓┊help
3y ago
Editing multiple images
FilamentFFilament / ❓┊help
3y ago
Permission denied when uploading images, PDFs work.
FilamentFFilament / ❓┊help
3y ago