Nested form image type not get stored value in edit action in laravel open-admin

139 Views Asked by At

I have one-to-many relationship tables called "Flag" and "flagimages". I want to store all my data in one form. Therefore, I created a nested form in "flagcontroller". I have a number of images, which each image has caption text for one flag. In adding a new record, it inserts all flag table fields and flagimages table fields. it means it saves all image paths in the database.

But the problem is when I go to edit action. After I submitted the edit form the image path value of flagimages table went to null. I can't fix this issue. There are no error messages shown in this case.

also I want to mention there is no edit function in open admin package

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Flag extends Model
{
    protected $table = 'flags';

    protected $fillable =[
        'small_description',
        'cover_photo',
        'cover_photocaption',
    ];


    public function flagimage()
    {
        return $this->hasMany(Flagimage::class, 'flag_id', 'id');
    }
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Flagimage extends Model
{
    protected $table = 'flagimages';

    protected $fillable = [
        'flag_id',
        'image_url',
        'image_caption',
    ];

    public function flag()
    {
        return $this->belongsTo(Flag::class, 'flag_id', 'id');
    }
}
protected function form()
    {
        $form = new Form(new Flag());

        $form->select('language_id', __('Language id'))->options(Language::all()->pluck('language_name', 'id'))->rules('required');
        $form->select('location_id', __('Location id'))->options(Location::all()->pluck('name', 'id'))->rules('required');
        $form->textarea('small_description', __('Small description'));
        $form->image('cover_photo', __('Cover photo'))->move('flag/cover')->uniqueName();
        $form->textarea('cover_photocaption', __('Cover photocaption'));

        $form->hasMany('flagimage', function (Form\NestedForm $form) {
            $form->image('image_url', __('Image'))->move('flag/images')->uniqueName();

            $form->textarea('image_caption', __('Caption'));
           

        });

        return $form;
    }

this is new added value form

edit form

DB for flagimages table

DB for flag table

this is database record after submitted the edit form

0

There are 0 best solutions below