© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
29 replies
yagrasdemonde

SpatieMediaLibraryFileUpload inside createOptionForm()

Hello,

I have an exception when I save record with SpatieMediaLibraryFileUpload inside createOptionForm =>
Call to undefined method App\Models\MealItems::getMedia()
Call to undefined method App\Models\MealItems::getMedia()


Explanation :

I have a form to save a meal. Inside it, I have a repeater to insert many dishes.
To do that I use
Forms\Components\Repeater::make('items')->schema([
Forms\Components\Select::make('dish_id')->options(Dish::pluck('name', 'id'))->createOptionForm([
    ...
SpatieMediaLibraryFileUpload::make('media')
        ->label('Image')
        ->collection('dishes-images')
        ->image()
])
->createOptionUsing(fn ($data) => Dish::create($data)->getKey())
])
Forms\Components\Repeater::make('items')->schema([
Forms\Components\Select::make('dish_id')->options(Dish::pluck('name', 'id'))->createOptionForm([
    ...
SpatieMediaLibraryFileUpload::make('media')
        ->label('Image')
        ->collection('dishes-images')
        ->image()
])
->createOptionUsing(fn ($data) => Dish::create($data)->getKey())
])

When I create new dish by clicking + button, a modal opens, all fields are saved in dishes table after submit, and this record is set to dish_id select of meal form but not my image in media table.
Then when I try to edit this meal, back to create a new dish clicking + button, and after submit button modal, I get this error
Call to undefined method App\Models\MealItems::getMedia()
Call to undefined method App\Models\MealItems::getMedia()
.

In fact is normal since HasMedia is in Dish model and not MealItems

Forms\Components\Repeater::make('items')
Forms\Components\Repeater::make('items')
items is the name of my relationship

How do I say to spatie to get ID of Dish created to permit to save image in media table ?

Thank you
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

SpatieMediaLibraryFileUpload inside a Repeater
FilamentFFilament / ❓┊help
2y ago
Pass state value inside the createOptionForm
FilamentFFilament / ❓┊help
4mo ago
Repeater acts differently when used inside createOptionForm
FilamentFFilament / ❓┊help
2y ago