Miquel Àngel
Miquel Àngel

Reputation: 164

Some attributes ignored when use subfields in a relationship

I'm using this relationship in a project.

        $this->crud->addField([
            'name' => 'laundryItems',
            'type' => 'relationship',
            'tab'  => 'Pieza a enviar',
            'label' => 'Piezas en el envío',
            // ..
            'subfields' => [

                [
                    'name' => 'qty',
                    'type' => 'number',
                    'label' => 'Cantidad TOTAL',
                    'hint'  => 'Total de piezas enviadas/recibidas',
                    'wrapper' => [
                        'class' => 'form-group col-md-3',
                    ]
                ],
                [
                    'name' => 'qtyDamaged',
                    'type' => 'number',
                    'label' => 'Cantidad Dañadas',
                    'hint'  => 'De las recibidas, cuántas dañadas',
                    'wrapper' => [
                        'class' => 'form-group col-md-3',
                    ]
                ],
                [
                    'name' => 'qtyDirty',
                    'type' => 'number',
                    'label' => 'Cantidad Sucias',
                    'hint'  => 'De las recibidas, cuántas sucias',
                    'wrapper' => [
                        'class' => 'form-group col-md-3',
                    ]
                ],
                [
                    'name' => 'comment',
                    'label' => 'Comentario',
                    'type' => 'textarea',
                    'wrapper' => [
                        'class' => 'form-group col-md-6',
                    ],
                ],
            ],
        ]);

which is working perfectly well. But now I want to use options and attribute but both are ignored until I delete the subfields property

So if I use

$this->crud->addField([
            'name' => 'laundryItems',
            'type' => 'relationship',
            'tab'  => 'Pieza a enviar',
            'label' => 'Piezas en el envío',
            'attribute' => 'pmsCode',
        ]);

attribute is applied, but if I add the subfields again, then not. That doesn't make any sense. I deleted the view cache but still the same issue.

PHP VERSION:

PHP 8.2.15 (cli) (built: Jan 20 2024 14:17:05) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.15, Copyright (c) Zend Technologies with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies

LARAVEL VERSION:

10.44.0.0

BACKPACK PACKAGE VERSIONS:

backpack/backupmanager: v5.0.0 backpack/basset: 1.2.2 backpack/crud: 6.6.3 backpack/devtools: 3.0.4 backpack/editable-columns: 3.0.5 backpack/generators: v4.0.3 backpack/logmanager: v5.0.1 backpack/permissionmanager: 7.1.1 backpack/pro: 2.1.3 backpack/settings: 3.1.0 backpack/theme-coreuiv2: 1.2.3 backpack/theme-coreuiv4: 1.1.1 backpack/theme-tabler: 1.2.0

Upvotes: 0

Views: 66

Answers (2)

Miquel Àngel
Miquel Àngel

Reputation: 164

I answer my self. It's very well documented, if you need to modify the primary select you have to use the attribute pivotSelect https://backpackforlaravel.com/docs/6.x/crud-fields#configuring-the-pivot-select-field

'pivotSelect'=> [
                'options' => function($model) {
                    return $model->where('active', 1);
                },
                'attribute' => 'pmsCode'
            ]

Upvotes: 0

Karan Datwani
Karan Datwani

Reputation: 775

The attribute property is used to specify column when we want a select dropdown from another table.

We use subfields when to show a form to create related table items directly from the CRUD.

If you want both in the same CRUD, you should consider creating related entries in a modal - using the InlineCreate Operation.

In your case, it looks like you want a dropdown to select items & define quantity. This is similar to an example defined in the docs here:

https://backpackforlaravel.com/docs/6.x/crud-fields#save-additional-data-to-pivot-table enter image description here

Upvotes: 0

Related Questions