morphTo relationship
In model
public function image(){ return $this->morphTo(Image::class, 'imageable')->where('position_slug', 'logo'); }
in filament resources
Fieldset::make('Metadata')
->relationship('image')
->schema([
FileUpload::make('image')->image(),
])
but it's not uploading image in relationship model. and my relational table is in given screenshot.
3 Replies
I think it needs to be
morphOne()
on the parent model and morphTo()
on the Image :
https://laravel.com/docs/10.x/eloquent-relationships#one-to-one-polymorphic-model-structureThank you, this is working for me