Missing field on relationship

I have this relationship fieldset
Fieldset::make('Address')
->relationship('address')
->schema([
Forms\Components\TextInput::make('city')
->required(),
Forms\Components\TextInput::make('state')
->required(),
Forms\Components\TextInput::make('zip')
->required(),
Forms\Components\TextInput::make('origin_country')
->disabled()
->dehydrated(false)
->readOnly(),
])
->mutateRelationshipDataBeforeFillUsing(fn ($data) => dd($data)),
Fieldset::make('Address')
->relationship('address')
->schema([
Forms\Components\TextInput::make('city')
->required(),
Forms\Components\TextInput::make('state')
->required(),
Forms\Components\TextInput::make('zip')
->required(),
Forms\Components\TextInput::make('origin_country')
->disabled()
->dehydrated(false)
->readOnly(),
])
->mutateRelationshipDataBeforeFillUsing(fn ($data) => dd($data)),
My issue is, in the $data, origin_country does not exist. But in the database it exists, in my model fillable it exists. Am I missing something?
7 Replies
awcodes
awcodes9mo ago
dehydrated(false) removes it from the form data.
Jamie Cee
Jamie CeeOP9mo ago
Ah, I misunderstood that, I read somewhere on google that it prevents the ability to update the field. Unless the disabled and readonly will do that for me? Preventing updating even through inspect element But even removing that, its still not coming through the form data. Despite having valid data
awcodes
awcodes9mo ago
Would have to check the spec but one of those might remove it from form submission too. Try just disabled or readonly separately. If it isn’t editable though it shouldn’t be needed in the form data anyway.
Jamie Cee
Jamie CeeOP9mo ago
Isn't editable, just want to display the current value
awcodes
awcodes9mo ago
ah, think I misunderstood. You're saying it's not in showing in the form to start with?
Jamie Cee
Jamie CeeOP9mo ago
Yeah I got it working, I think. With this:
Fieldset::make('Address')
->relationship('address')
->schema([
Forms\Components\TextInput::make('city')
->required(),
Forms\Components\TextInput::make('state')
->required(),
Forms\Components\TextInput::make('zip')
->required(),
Forms\Components\TextInput::make('origin_country')
->disabled()
->readOnly(),
])
->mutateRelationshipDataBeforeFillUsing(function ($data, $record) {
$data['origin_country'] = $record->address->origin_country;
return $data;
}),
Fieldset::make('Address')
->relationship('address')
->schema([
Forms\Components\TextInput::make('city')
->required(),
Forms\Components\TextInput::make('state')
->required(),
Forms\Components\TextInput::make('zip')
->required(),
Forms\Components\TextInput::make('origin_country')
->disabled()
->readOnly(),
])
->mutateRelationshipDataBeforeFillUsing(function ($data, $record) {
$data['origin_country'] = $record->address->origin_country;
return $data;
}),
edson36
edson369mo ago
I have the same problem, but the textinput needs to be editable, and when I modify the data within mutate the change is ok, but it doesn't update the textinput
Want results from more Discord servers?
Add your server