Reputation: 34
I have a problem to use morphable related selects in subfields of laravel backpack. Actually, How can I use this code in backpack subfields?
CRUD::field('colorable')
->label(trans('translate.to'))
->addMorphOption('App\Models\PlexiColor', trans("translate.plexi_color"), [
'type' => 'select2_from_ajax',
'attribute' => "name",
'entity' => 'colorable',
'model' => "App\Models\PlexiColor",
'data_source' => backpack_url('board-color-price/fetch/plexi-color'),
'minimum_input_length' => 0,
'method' => 'POST',
'include_all_form_fields' => true,
])
->addMorphOption('App\Models\MultiStyleColor', trans("translate.multistyle_colors"), [
'type' => 'select2_from_ajax',
'attribute' => "name",
'entity' => 'colorable',
'model' => "App\Models\MultiStyleColor",
'data_source' => backpack_url('board-color-price/fetch/multistyle-color'),
'minimum_input_length' => 0,
'method' => 'POST',
'include_all_form_fields' => true,
])
->addMorphOption('App\Models\StealColor', trans("translate.steal_colors"), [
'type' => 'select2_from_ajax',
'attribute' => "name",
'entity' => 'colorable',
'model' => "App\Models\StealColor",
'data_source' => backpack_url('board-color-price/fetch/steal-color'),
'minimum_input_length' => 0,
'method' => 'POST',
'include_all_form_fields' => true,
])
->addMorphOption('App\Models\PleximirrorColor', trans("translate.Pleximirror_colors"), [
'type' => 'select2_from_ajax',
'attribute' => "name",
'entity' => 'colorable',
'model' => "App\Models\PleximirrorColor",
'data_source' => backpack_url('board-color-price/fetch/pleximirror-colors'),
'minimum_input_length' => 0,
'method' => 'POST',
'include_all_form_fields' => true,
])
->morphTypeField(['wrapper' => ['class' => 'form-group col-md-6']])
->morphIdField(['wrapper' => ['class' => 'form-group col-md-6'], 'placeholder' => trans('translate.choose'),]);
I did many things but it doesn't work! for example: I use addMorphOption like array in subfield but it doesn't work.
Upvotes: 0
Views: 111
Reputation: 6193
Unfortunately, morph fields cannot currently be used as subfields - as of Backpack v5. We recommend you split up this form into multiple forms. You can easily allow the admin to create a related entry in a different form, in a modal, by using the InlineCreate operation - https://backpackforlaravel.com/docs/5.x/crud-fields#create-related-entries-in-a-modal-using-the-inlinecreate-operati
Upvotes: 1