Edit form not bringing data from the related table
Hello. Could anyone help me? When calling the edit form below, it is not bringing data from the related table. For example: The Model Client has an address_id, but when calling the form to update the client data, it does not return the address values in the inputs.
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Fieldset::make('Dados do cliente')
->schema([
Forms\Components\TextInput::make('name')
->label('Nome')
->columnSpan(2)
->required(),
Forms\Components\TextInput::make('email')
->label('E-mail')
->email(),
Forms\Components\TextInput::make('phone')
->label('Telefone')
->mask('(99) 99999-9999')
->tel(),
])
->columns(2),
Forms\Components\Fieldset::make('Endereço do cliente')
->schema([
Forms\Components\TextInput::make('address.postal_code')
->label('CEP')
->mask('99999-999')
->string()
->nullable(),
...
The code returns this:
12 Replies
Is that a relation? May be those data needs to be loaded from a related model and you may not have defined a relation.
follow prints of relationships
https://filamentphp.com/docs/3.x/forms/advanced#saving-data-to-relationships
You need to make field set or group.
When adding the relationship name as shown, the address field data remained empty.
Sounds like your relationship is not set up correctly.
My Client Model:
That looks ok. Can you confirm that your db has an ID for the address on that record?
Yes. Contains the id of the correctly associated record.
If I put the relationship in the main form, the opposite happens. Returns only the Address data and not the Client.
https://discord.com/channels/883083792112300104/1189209591691616266/1189219704032739479
hmmm. nothing obvious is standing out to me based on what you're shared.
I realized that when I added the relationship ('address') I am no longer able to receive customer data in the protected function handleRecordCreation(array $data): Model, only the address data. That's why it doesn't show on the form either
Hello. Could anyone help me?
If you delete your custom
handleRecordCreation()
function, does it retrieve and save correctly? I'm puzzled about what you're customizing by using that override.