© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•10mo ago•
3 replies
SoraKeyheart

FileUpload dynamic directory issue

I've build a Fileupload Helper like so to be reusable across resources:

class FileUploadHelper
{
    /**
     * Create a standardized file upload component
     *
     * @param bool   $required
     */
    public static function createFileUpload(
        string $name,
        string $label,
        string $directoryName,
        string $prefix,
        string $dbColumn,
        string $subdirectory,
        array $options): FileUpload
    {
        $upload = FileUpload::make($name)
            ->label(__($label))
            ->directory(
                fn (Get $get): string => $directoryName . '/'
                    . ($get('prefix') ?? $prefix . '#' . str_pad((string)$get($dbColumn), 4, '0', STR_PAD_LEFT))
                    . '/'
                    . $subdirectory
            )
            ->openable();

            // Options
            if (isset($options['hiddenLabel']) ?? false) {
                $upload->hiddenLabel();
            }

            // Some more ...

            return $upload;
    }
}
class FileUploadHelper
{
    /**
     * Create a standardized file upload component
     *
     * @param bool   $required
     */
    public static function createFileUpload(
        string $name,
        string $label,
        string $directoryName,
        string $prefix,
        string $dbColumn,
        string $subdirectory,
        array $options): FileUpload
    {
        $upload = FileUpload::make($name)
            ->label(__($label))
            ->directory(
                fn (Get $get): string => $directoryName . '/'
                    . ($get('prefix') ?? $prefix . '#' . str_pad((string)$get($dbColumn), 4, '0', STR_PAD_LEFT))
                    . '/'
                    . $subdirectory
            )
            ->openable();

            // Options
            if (isset($options['hiddenLabel']) ?? false) {
                $upload->hiddenLabel();
            }

            // Some more ...

            return $upload;
    }
}


it's working like charm, here is how it is used in the resource:

FileUploadHelper::createFileUpload(
    name: 'accident_images',
    label: 'Accident Images',
    directoryName: 'Accidents',
    prefix: 'MVA',
    dbColumn: 'ac_number',
    subdirectory: 'Accident Images',
    options: [
        'required' => true,
        'image' => true,
        'multiple' => true,
        'maxFiles' => 20,
        'imagePreviewHeight' => 250,
        'panelLayout' => 'grid',
        'hint' => "Make sure the files are in any image format (jpg, jpeg, png, webp, gif)",
        'hintColor' => 'primary',
    ]
),
FileUploadHelper::createFileUpload(
    name: 'accident_images',
    label: 'Accident Images',
    directoryName: 'Accidents',
    prefix: 'MVA',
    dbColumn: 'ac_number',
    subdirectory: 'Accident Images',
    options: [
        'required' => true,
        'image' => true,
        'multiple' => true,
        'maxFiles' => 20,
        'imagePreviewHeight' => 250,
        'panelLayout' => 'grid',
        'hint' => "Make sure the files are in any image format (jpg, jpeg, png, webp, gif)",
        'hintColor' => 'primary',
    ]
),


In short, each accident has a reference number (MVA#0000). The files are uploaded correctly to the dynamic folders. but when I access the edit/view page of the record, the images are not showing, and when trying to access them though url I get 404 not found (see attached).

May you please assist me with solving/tracing this?
Thank you
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dynamic directory for FileUpload
FilamentFFilament / ❓┊help
3y ago
FileUpload directory closure
FilamentFFilament / ❓┊help
3y ago
Fileupload directory on create
FilamentFFilament / ❓┊help
3y ago
fileupload issue preview issue
FilamentFFilament / ❓┊help
3y ago