© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•4mo ago•
1 reply
BerriesAndCream

SpatieMediaLibraryFileUpload on a related record

I have a User model and a Customer model, they have a one-to-one relationship with each other.

User model implements the
Spatie\MediaLibrary\HasMedia
Spatie\MediaLibrary\HasMedia
and uses the
Spatie\MediaLibrary\InteractsWithMedia
Spatie\MediaLibrary\InteractsWithMedia
trait.

Using SpatieMediaLibraryFileUpload component in a form in User resource works fine, it loads the media when you're in the Edit page.

For the Customer resource, it doesn't load on edit page even when I put a
->relationship('user')
->relationship('user')
in a layout form component like Section.
  // CustomerForm.php
  Section::make('Customer ')
    ->relationship('user')
    ->schema([
        SpatieMediaLibraryFileUpload::make('avatar')
            ->collection('avatar')
            ->avatar()
            ->columnSpanFull(),
    ]),
  // CustomerForm.php
  Section::make('Customer ')
    ->relationship('user')
    ->schema([
        SpatieMediaLibraryFileUpload::make('avatar')
            ->collection('avatar')
            ->avatar()
            ->columnSpanFull(),
    ]),


My current solution for this is :
  // EditCustomer.php
  protected function getHeaderActions(): array
    {
        $isFirstLoad = empty($this->data['user']['avatar']);
        $avatar = $this->record->user->getFirstMedia('avatar')?->uuid;
        
        if ($isFirstLoad && $avatar) {
            data_set($this->data['user'], 'avatar', [$avatar => $avatar]);
        }
        
        return [
            ViewAction::make(),
            DeleteAction::make(),
        ];
    }
  // EditCustomer.php
  protected function getHeaderActions(): array
    {
        $isFirstLoad = empty($this->data['user']['avatar']);
        $avatar = $this->record->user->getFirstMedia('avatar')?->uuid;
        
        if ($isFirstLoad && $avatar) {
            data_set($this->data['user'], 'avatar', [$avatar => $avatar]);
        }
        
        return [
            ViewAction::make(),
            DeleteAction::make(),
        ];
    }


I was wondering if there's a more "native" approach for this.
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

canViewAny on Manage Related Record.
FilamentFFilament / ❓┊help
2y ago
How to refresh related record on a resource page?
FilamentFFilament / ❓┊help
3y ago
How to show total count of related record on Manage Related Record tab badge ?
FilamentFFilament / ❓┊help
2y ago
Displaying related pivot record details on table
FilamentFFilament / ❓┊help
2y ago