Heello everyone!
I have a product crud controller in my project and I want to assign specifications and their values (pivot table of the products and the specifications tables), and also the specification groups (pivot table of the products and the specification groups), to it simultaneously. I'm stuck in here, because I cannot have one subfields inside another. Appreciate any suggestions to solve this.
Here are the details:
My database structure is as follows (NO JSON COLUMNS IN DATABASE):
- The products table has one-to-many relationship with the categories table
- The categories table has many-to-many relationship with the specification_groups table
- The specification_groups table has many-to-many relashionship with the specifications table
- The specifications table has many-to-many relationship with the products table (the values of each product's specification will be inserted inside this pivot table)
- And, the specification_groups table has many-to-many relationship with the products table
I tried unsuccessfully to fill the last two pivot tables, using two relationships, as follows (I want that the Admin sees repeatable rows or tables rows of specification_group (select) -> specification (select) -> value (text field to be filled by the Admin)
):
CRUD::addField([
'name' => 'specificationGroups',
'label' => "Specifications",
'type' => 'relationship',
'init_rows' => 1,
'min_rows' => 1,
'tab' => 'Specifications',
'pivotSelect' => [
'entity' => 'specificationGroups',
'model' => "App\Models\SpecificationGroup",
'attribute' => 'name',
'ajax' => true,
'data_source' => backpack_url("product/fetch/specification-group"),
'dependencies' => ['category_id'],
'method' => 'POST',
'minimum_input_length' => 0,
"include_all_form_fields" => true,
'wrapper' => [
'class' => 'form-group col-md-6',
],
],
'subfields' => [
[
'name' => 'sort',
'type' => 'number',
'attributes' => ["min" => "1"],
'wrapper' => [
'class' => 'form-group col-md-6',
],
],
[
'name' => 'specifications',
'label' => "Specification",
'type' => 'relationship',
'init_rows' => 1,
'min_rows' => 1,
'pivotSelect' => [
'entity' => 'specifications',
'model' => "App\Models\Specification",
'attribute' => 'name',
'ajax' => true,
'data_source' => backpack_url("product/fetch/specification"),
'dependencies' => ['category_id', 'specificationGroups'],
'method' => 'POST',
'minimum_input_length' => 0,
"include_all_form_fields" => true,
],
'subfields' => [
[
'name' => 'value',
'type' => 'text',
'wrapper' => [
'class' => 'form-group col-md-12',
],
],
[
'name' => 'sort',
'type' => 'number',
'attributes' => ["min" => "1"],
'wrapper' => [
'class' => 'form-group col-md-12',
],
],
],
],
],
]);
I rellay appreciate any suggestions for implementing this insert.