关系管理器未显示数据透视表数据 [英] Relation Manager Not Showing Pivot Data

查看:132
本文介绍了关系管理器未显示数据透视表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此出现此问题的原因是

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

因此,我有点涉猎后端表单,并以为自己知道如何解决这个问题.但是,我没有看到我认为会得到的结果.我试图做一些研究,还没有看到有人在github页面或stackoverflow的问题中提到这一点.除非我错过了. 您如何在后端显示存储的额外数据透视数据?

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?

这是我的model.php关系:

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

这是我的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';

这是我的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:

推荐答案

因此,我在阅读并阅读了laravel文档后解决了这个问题.解决方案是在模型关系配置中添加pivot => ['quantity'].

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']
    ]
];

这篇关于关系管理器未显示数据透视表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆