Laravel-admin: Help with $form-saving (relation)

Created on 23 Aug 2018  ·  2Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: #.#.#
  • PHP Version:
  • Laravel-admin: #.#.#

Description:

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.

Steps To Reproduce:

        $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']);     
        });

Most helpful comment

Use $form->input();

$form->saving(function ($form) {
    $form->input('address.cep', preg_replace( '#[^0-9]#', '', $form->address['cep']));
});

All 2 comments

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']));
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

amun1303 picture amun1303  ·  3Comments

joernroeder picture joernroeder  ·  3Comments

MarKco picture MarKco  ·  3Comments

piian picture piian  ·  3Comments

zhenyangze picture zhenyangze  ·  3Comments