I have a HasOne relationship in a form, but during the save I need to modify an address information field address['CEP'] which is a measure of the parent table. But I'm getting an error
Indirect modification of overloaded property Encore\Admin\Form::$address has no effect
can anyone help me how to change this field before saving.
$form->row(function ($row) use ($form) {
$row->width(2)->text('address.cep', 'CEP *')
->attribute(['data-inputmask' => '"mask": "99 999-999"'])
->placeholder('00 000-000');
});
$form->saving(function (Form $form)
{
$form->address['cep'] = preg_replace( '#[^0-9]#', '', $form->address['cep']);
});
I was able to solve
$arrAddress = $form->address;
$arrAddress['cep'] = preg_replace( '#[^0-9]#', '', $arrAddress['cep']);
$form->address = $arrAddress;
Use $form->input();
$form->saving(function ($form) {
$form->input('address.cep', preg_replace( '#[^0-9]#', '', $form->address['cep']));
});
Most helpful comment
Use
$form->input();