When building Filament forms, you can use layout components to logically and visually group fields. Some layout components have a relationship() method that allows you to define that the data in this component belongs to a relationship, not to the base model.
For example, if you’re building a page to edit users and you have the user’s address in a separate table, you could add this inside the schema definition in your user resource’s form() method:
Section::make('Address')
->relationship('address')
->schema([
TextInput::make('street'),
TextInput::make('zip'),
TextInput::make('state'),
TextInput::make('country'),
TextInput::make('phone'),
])
That will make sure that clicking the “Save” button at the bottom of the page will also update the appropriate row in the addresses table.
But what do you do when you have a section that doesn’t just have data belonging to the relationship, but also to the base model itself? For example, say the user’s phone number is actually stored directly in the users table, and not in the addresses table. In that case, the phone field on the page will be empty, because Filament is looking for $user->address->phone instead of $user->phone. Saving the form will then obviously also not update the phone number.
(This is a stupid example, of course – saving an address in a separate table, but a phone number in the main table would be idiotic. The principle still applies, though, that sometimes the way data is arranged in the database isn’t the most intuitive way to present it to an admin editing the resource.)
Is there a way to tell Filament that a particular field does not belong to the relationship defined for the layout component, but should be scoped to the parent model?