open-admin icon indicating copy to clipboard operation
open-admin copied to clipboard

MorphMany relation problem on dynamic NestedForm

Open Alionides opened this issue 8 months ago • 0 comments

Describe the bug When you create morphMany relation to another table and use it main table to create dynamic forms everything is working except image update. If you add second form image then first forms image is disappearing from database and set it to 0 value.

I have Home model and Slider model Code example: in HomePageController in Admin folder of open-admin admin panel.

protected function form()
    {
        $form = new Form(new Home());
        $form->tab('General', function ($form) {
            $form->text('seo_title_az', __('Seo title az'));
            $form->textarea('seo_desc_az', __('Seo desc az'));
            $form->text('seo_title_en', __('Seo title en'));
            $form->textarea('seo_desc_en', __('Seo desc en'));
            $form->text('slug', __('Slug'));
        });

        $form->tab('Slider', function ($form) {
            $form->morphMany('sliders', function (Form\NestedForm $form) {
                $form->text('title_en');
                $form->textarea('desc_en');
                $form->image('image_first', __('First image'));
                $form->image('image_second', __('Second image'));
                $form->radio('active', __('Active'))->options([
                    1 => 'Active',
                    0 => 'Inactive',
                ])->default(1);
            });
        });

        return $form;
    }
}

System

  • Open-admin version ^1.0
  • PHP version 8.1
  • Laravel Version 10
  • OS: [Linux]
  • Browser [firefox]

Alionides avatar Jun 25 '24 11:06 Alionides