© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
NikSpyratos

How do form fields with relationships work?

I'm using the spatie roles and permissions on my Filament panel, and would like to write some tests to assert that permissions change appropriately in my
EditRole
EditRole
form. The result I'm seeing is that in my tests if I populate the
permissions
permissions
form field with permission IDs, no changes are being saved specifically in the test. So I thought I'd dive in to see how the relation fields work.

I have the following:
Select::make('permissions')
    ->relationship('permissions', 'displayName')
    ->multiple()
    ->preload()
    ->hiddenOn('view'),
Select::make('permissions')
    ->relationship('permissions', 'displayName')
    ->multiple()
    ->preload()
    ->hiddenOn('view'),

But I can't figure out where Filament actually processes this for saving -
handleRecordUpdate
handleRecordUpdate
and
mutateFormDataBeforeSave
mutateFormDataBeforeSave
don't have any
permissions
permissions
key, but the permissions update just fine.
Solution
It's the
saveRelationshipUsing()
saveRelationshipUsing()
code. That's defined from the
->relationship()
->relationship()
method.
Select
Select
file line 953 to 980
Jump to solution
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

Nesting form fields depending on relationships
FilamentFFilament / ❓┊help
2y ago
Testing form with relationships
FilamentFFilament / ❓┊help
2y ago
Reused form fields do not seem to follow model relationships
FilamentFFilament / ❓┊help
3y ago
Form relationships
FilamentFFilament / ❓┊help
2y ago