Get Collection from related model using Spatie Media Library plugin
Hello, in my project we use spatie media library to manage media files, let's say that I have 2 models and one belongsTo the other: Hotel and Room, Hotel has a media collection, i.e. "hotel_photos". What approach do I need to display the "hotel_photos" in the HouseResource form? the component SpatieMediaLibraryFileUpload only retrieves collections that belongs to the $record.
Thanks.
Solution:Jump to solution
I found the answer, defining a Fieldset component with a relationship changes the scope of the $record, i.e.:
[ RoomResource form ]
...
Fieldset::make('hotel')
->relationship('hotel')...
1 Reply
Solution
I found the answer, defining a Fieldset component with a relationship changes the scope of the $record, i.e.:
[ RoomResource form ]
...
Fieldset::make('hotel')
->relationship('hotel')
->schema([
SpatieMediaLibraryFileUpload::make('hotel_photos')
->collection('hotel_photos'),
])
...