Relation Manager Not Showing Pivot Data

∥☆過路亽.° 提交于 2020-04-17 21:53:13

问题


So this question came about because of this other question I was looking into.

So I have dabbled in this a bit working with backend forms and thought I knew how to tackle this. However I am not seeing the results that I thought I would. I have tried to do some research and haven't seen anyone bring this up in the issues on the github page or here in stackoverflow. Unless I missed it. How do you show the stored extra Pivot Data in the backend?

Here is my model.php relationship:

public $belongsToMany = [
    'equipments' => [
        'Brandon\Pixelrpg\Models\Equipments',
        'table' => 'brandon_pixelrpg_equipment_inventory',
        'key' => 'inventory',
        'otherKey' => 'equipment'
    ]
];

Here is my controller.php:

public $implement = [        
    'Backend\Behaviors\ListController',
    'Backend\Behaviors\FormController',
    'Backend\Behaviors\ReorderController',
    'Backend\Behaviors\RelationController'
];

public $listConfig = 'config_list.yaml';
public $formConfig = 'config_form.yaml';
public $reorderConfig = 'config_reorder.yaml';
public $relationConfig = 'config_relation.yaml';

Here is my config_relation.yaml:

equipments:
    label: Equipments
    view:
        list:
            columns:
                id:
                    label: ID
                    type: number
                    searchable: true
                    sortable: true
                name:
                    label: Name
                    type: text
                    searchable: true
                    sortable: true
                value:
                    label: Value
                    type: number
                    searchable: true
                    sortable: true
                updated_at:
                    label: Updated
                    type: datetime
                    searchable: true
                    sortable: true
                pivot[quantity]:
                    label: Quantity
                    type: number

    pivot:
        form:
            fields:
                pivot[quantity]:
                    label: Quantity
                    type: number
                    default: 0

So here is my backend form showing correctly the relation manager. You will noticed that the quantity field is not being filled out. In the second image of my database it does correctly get filled out updated and deleted using the form:


回答1:


So I solved this after digging around and reading laravel documents. The solution was to add pivot => ['quantity'] in the model relationship configuration.

public $belongsToMany = [
    'equipments' => [
        'Brandon\Pixelrpg\Models\Equipments',
        'table' => 'brandon_pixelrpg_equipment_inventory',
        'key' => 'inventory',
        'otherKey' => 'equipment',
        'pivot' => ['quantity']
    ]
];


来源:https://stackoverflow.com/questions/61111322/relation-manager-not-showing-pivot-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!