© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
7 replies
Dos

Optionally adding a morthOne relationship for the resource form

There is an Item model with a morphOne relationship to the Attachments model.

In the ItemResource form when creating an Item, the ability to add an attachment for the item is also added, but it should be optional, not mandatory.

The problem is that if I don't load the attachment, an error is returned because when I create Item at the same time it tries to create the Attachment relationship on null

I would appreciate if anyone advise me If there is a way to add an attachment optionally ItemResource form?

Section::make('Attachments')->schema([
                                                FileUpload::make('url')
                                                            ->required()
                                                            ->downloadable()
                                                            ->label('File'),
                                                        ])->relationship('attachments')
Section::make('Attachments')->schema([
                                                FileUpload::make('url')
                                                            ->required()
                                                            ->downloadable()
                                                            ->label('File'),
                                                        ])->relationship('attachments')
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

Adding a "hasOne" relationship in the resource view.
FilamentFFilament / ❓┊help
2y ago
relationship on a resource
FilamentFFilament / ❓┊help
3y ago
Show dedicated resource view for a relationship
FilamentFFilament / ❓┊help
3y ago