Laravel-admin: [bug]Embeds Form field not working when inserting data

Created on 1 May 2018  ·  4Comments  ·  Source: z-song/laravel-admin

  • Laravel Version: 5.5.*
  • PHP Version: 7.1.*
  • Laravel-admin: 1.5-dev

Description:

If I set Embeds fields

ExampleController.php return Admin::form(ExModel::class, function (Form $form) { $form->embeds('value', function (Form\EmbeddedForm $form) { $form->text('extra1')->rules('required'); //$form->email('extra2')->rules('required'); //$form->mobile('extra3'); //$form->datetime('extra4'); }); $form->display('created_at', 'Created At'); $form->display('updated_at', 'Updated At'); });

When I saved as creating, column "value" is null, but when I saved as updating, column "value" is saveing as json.

I investigated "Form.php", and I found the function "isHasOneRelation" in "prepareInsert" is true.
I think the function "isHasOneRelation" is for relationship "hasOne", but using embed, it's true. so, the "value" array converts to flatten dotted string, it's wrong.

How to reslove this?

--

Steps To Reproduce:

Most helpful comment

Yes something like that, I added another field before embeds, I have not
tested hidden, I added a text or select field.

On Mon, May 14, 2018 at 11:49 AM, hirossyi73 notifications@github.com
wrote:

@gozhhu https://github.com/gozhhu
Thanks a comment.

What you say the mean is adding a column before "$form->embeds"?

ex.

return Admin::form(ExModel::class, function (Form $form) {
$form->hidden('foobar'); // ←add.
$form->embeds('value', function (FormEmbeddedForm $form) {
$form->text('extra1')->rules('required');
//$form->email('extra2')->rules('required');
//$form->mobile('extra3');
//$form->datetime('extra4');
});
$form->display('created_at', 'Created At');
$form->display('updated_at', 'Updated At');
});


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/z-song/laravel-admin/issues/1998#issuecomment-388689219,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJVMA7oZRhYmKDmnFAnO4GmVhzEb4krks5tyP6zgaJpZM4TttRl
.

All 4 comments

Yes I just found this problem too. I can remove this line to prevent array_dot, but I need to change the vendor's source code.
isHasOneRelation($inserts) only checks the first column of inserts, so I put a non-json column to first.

And the problem is solved....

@gozhhu
Thanks a comment.

What you say the mean is adding a column before "$form->embeds"?

ex.

return Admin::form(ExModel::class, function (Form $form) {
            $form->hidden('foobar'); // ←add.
            $form->embeds('value', function (Form\EmbeddedForm $form) {
                $form->text('extra1')->rules('required');
                //$form->email('extra2')->rules('required');
                //$form->mobile('extra3');
                //$form->datetime('extra4');
            });
            $form->display('created_at', 'Created At');
            $form->display('updated_at', 'Updated At');
        });

Yes something like that, I added another field before embeds, I have not
tested hidden, I added a text or select field.

On Mon, May 14, 2018 at 11:49 AM, hirossyi73 notifications@github.com
wrote:

@gozhhu https://github.com/gozhhu
Thanks a comment.

What you say the mean is adding a column before "$form->embeds"?

ex.

return Admin::form(ExModel::class, function (Form $form) {
$form->hidden('foobar'); // ←add.
$form->embeds('value', function (FormEmbeddedForm $form) {
$form->text('extra1')->rules('required');
//$form->email('extra2')->rules('required');
//$form->mobile('extra3');
//$form->datetime('extra4');
});
$form->display('created_at', 'Created At');
$form->display('updated_at', 'Updated At');
});


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/z-song/laravel-admin/issues/1998#issuecomment-388689219,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJVMA7oZRhYmKDmnFAnO4GmVhzEb4krks5tyP6zgaJpZM4TttRl
.

Sorry, response too late.
I resolved using hidden field.
But I wish we resolve this fundamental bugs.

Was this page helpful?
0 / 5 - 0 ratings