FilamentF
Filament12mo ago
steexd

How to safely override Filament core components methods?

Hi everyone!

I’ve made a couple of small modifications directly to Filament’s core BaseFileUpload class (in vendor/filament/filament/src/Forms/Components/BaseFileUpload.php), specifically in two methods,
removeUploadedFile(string $fileKey) and reorderUploadedFiles(array $fileKeys), adding this line: $this->callAfterStateUpdated();

I added this call to callAfterStateUpdated() so that my additional logic inside every FileUpload->afterStateUpdated() can run.

The problem is that these changes will be lost if I update or reinstall my Composer dependencies. So, what’s the recommended way to override or hook into these methods without directly modifying Filament core files?

Thank you in advance!
Solution
Hello
You can Create a new class that extends BaseFileUpload and override the methods up there ...

class CustomFileUpload extends BaseFileUpload
{
    protected function removeUploadedFile(string $fileKey): void
    {
        .....
    }

Then use it
Was this page helpful?