Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.18k stars 898 forks source link

[Bug] Allow user to select multiple times the same pivot #5707

Open rezahmady opened 1 month ago

rezahmady commented 1 month ago

after fix this reported issue 5635 this feature stopped working Allow user to select multiple times the same pivot

pxpm commented 1 month ago

Hello @rezahmady thanks for the report.

Can you provide some reproduction steps ? (ideally a simple repository we can clone to test your code with only the relevant model/migrations and crud controllers to reproduce this scenario).

We have some tests in place, and they are passing https://github.com/Laravel-Backpack/CRUD/blob/dee2eeca96190ade092bc2777c95275ec3d4130c/tests/Unit/CrudPanel/CrudPanelCreateTest.php#L795

Cheers

rezahmady commented 1 week ago

my relation in Video model:

public function crew_people(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany(CrewPeople::class,'crew_people_video', 'video_id', 'crew_people_id')
            ->withPivot(['crew_role_id', 'id', 'star']);
    }

this is my field


                [
                    'name'          => 'crew_people',
                    'type'          => "relationship",
                    'label' => '',
                    'allow_duplicate_pivots' => true,
                    'new_item_label'  => trans('crew::lang.add_crew_people'),
                    'tab' => trans('crew::lang.crew_people_plural'),
                    'subfields'   => [
                        [
                            'name' => 'crew_role_id',
                            'label' => trans('crew::lang.crew_role_singular'),
                            'type' => "select2_from_array",
                            'options' => CrewRole::pluck('name', 'id')->toArray(),
                            'wrapper' => [
                                'class' => 'form-group col-md-4',
                            ],
                            'placeholder' => trans('crew::lang.crew_role_plural_placeholder'),
                        ],
                        [
                            'name' => 'star',
                            'label' => trans('crew::lang.crew_star'),
                            'type' => "switch",
                            'wrapper' => [
                                'class' => 'form-group col-md-2 pt-5',
                            ],
                        ]
                    ],
                    'pivotSelect'=> [
                        // 'attribute' => "title", // attribute on model that is shown to user
                        'label' => trans('crew::lang.crew_people_singular'),
                        'placeholder' => trans('crew::lang.crew_placeholder'),
                        'wrapper' => [
                            'class' => 'col-md-6',
                        ],
                        'inline_create' => true,
                        // note that just like any other select, enabling ajax will require you to provide an url for the field
                        // to fetch available options. You can use the FetchOperation or manually create the enpoint.
                        'ajax' => true,
                        'minimum_input_length'    => 0,
                        'data_source' => url('/api/crew/people'),
                    ],
                ]

but result

image

I can't choose Eddie (first item) twice

whene i remove this line in field properties is correct

'inline_create' => true,

the main problem is inline create