filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.07k stars 2.82k forks source link

`SpatieMediaLibraryImageColumn` is empty when using `$this->form->fill(...)` #8195

Closed bilogic closed 1 year ago

bilogic commented 1 year ago

Package

filament/spatie-laravel-media-library-plugin

Package Version

3.0.38

Laravel Version

10.21.0

Livewire Version

3.0.1

PHP Version

8.1.20

Problem description

  1. I have a StaffResource that has a Image field typed as SpatieMediaLibraryImageColumn
  2. When editing the StaffResource, Image loads correctly
  3. I also needed a custom Page where the staff can edit their own profile, which I used the following

    public function mount(): void
    {
        $staff = Staff::find($id);
    
        dd($staff->toArray()); // `image` has the value of [] here...
    
        $this->form->fill($staff->toArray());
    }
  4. I tried looking into EditStaff.php but was not able to gain any insights.
  5. How do I make the profile page load image like the EditStaff page? Problem seems to be that $staff->toArray() returns an empty Image
  6. The solution seems elusive after trying and testing many things as detailed here https://github.com/filamentphp/filament/discussions/8166

Expected behavior

The Image field should show the currently saved image instead of having it blank

Steps to reproduce

  1. Please clone https://github.com/bilogic/filament-spatie-upload-issue and update .env
  2. Create a staff with an image and name (record ID should be 1)
  3. Load /admin/test and see the staff's name, but not the uploaded image

Reproduction repository

https://github.com/bilogic/filament-spatie-upload-issue

Relevant log output

No response

bilogic commented 1 year ago

Making $this->staff public solved the issue. Thank you.