F
Filament12mo ago
Moreira

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
Pulpsting0610
Pulpsting061012mo ago
Is that a relation? May be those data needs to be loaded from a related model and you may not have defined a relation.
Moreira
MoreiraOP12mo ago
follow prints of relationships
awcodes
awcodes12mo ago
Forms\Components\Fieldset::make('Endereço do cliente')
->relationship('address')
->schema([
Forms\Components\TextInput::make('postal_code')
->label('CEP')
->mask('99999-999')
->string()
->nullable(),
Forms\Components\Fieldset::make('Endereço do cliente')
->relationship('address')
->schema([
Forms\Components\TextInput::make('postal_code')
->label('CEP')
->mask('99999-999')
->string()
->nullable(),
Moreira
MoreiraOP12mo ago
When adding the relationship name as shown, the address field data remained empty.
awcodes
awcodes12mo ago
Sounds like your relationship is not set up correctly.
Moreira
MoreiraOP12mo ago
My Client Model:
awcodes
awcodes12mo ago
That looks ok. Can you confirm that your db has an ID for the address on that record?
Moreira
MoreiraOP12mo ago
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
awcodes
awcodes12mo ago
hmmm. nothing obvious is standing out to me based on what you're shared.
Moreira
MoreiraOP12mo ago
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?
DrByte
DrByte12mo ago
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.
Want results from more Discord servers?
Add your server