Skip to content

Form Embeds, Insertion not working with Json field. #4173

@redamakhchan

Description

@redamakhchan
  • Laravel Version: 6.5.1
  • PHP Version: 7.2
  • Laravel-admin: 1.7

Description:

I have an issue with Form Embeds Insertion (But edit is working fine).
Inspecting about the issue I found that on vendor/encore/laravel-admin/src/Form.php:1017.

$inserts = Arr::dot($inserts); changes the submitted data's format from an array to multiple fields, in my case :

From

"personalinfo" => [
    "name" => "reda",
    "mobile" => "066666"
]

To

"personalinfo.name" => "reda",
"personalinfo.mobile" => "066666"

Thing that doesn't allow this field to be known to Database (there is no column with name personalinfo.name but with personalinfo is).

Steps To Reproduce:

Have a Json Field on Migration :

$table->json('personalinfo')->nullable(false);

Controller form() method add Field as Embeds :

protected function form()
    {
        $form = new Form(new SpecialRequest);

        $form->embeds('personalinfo', 'Informations', function ($form) {
            $form->text('name');
            $form->text('mobile');
        });
        ...
    }

Model add $casts of the field :

protected $casts = [
        'personalinfo' => 'json',
    ];

Now try to add new Item with the Embeds fields, the field is not part of the informations submitted to Database.
Since Field on Database doesn't allow null, I receive :

SQLSTATE[HY000]: General error: 1364 Field 'personalinfo' doesn't have a default value (SQL: insert into special_requests (booking_id, date_start, price, description) values (0, 2019-11-22 16:06:00, 0, ezr))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions