如何在10月CMS后端的数据库中添加多选值?

时间:2016-06-14 10:38:23

标签: laravel-5 octobercms

enter image description here

未在数据库中插入多选值。

我的fields.yaml代码是:

 related_recipe:
        label: 'Related Recipe'
        span: auto
        nameFrom: recipe_title
        descriptionFrom: description
        attributes: {multiple:'multiple'}
        type: relation

我的型号代码是:

public $belongsTo = [

                    'related_recipe' => [
                         'Qdata\Taeq\Models\Recipe',
                      'conditions' => 'status = 1'
                      ],

                 ];

目前在database.need中只插入一个选定值,在数据库中添加多个值。任何人都可以解决它吗?

2 个答案:

答案 0 :(得分:0)

在这种情况下,你应该使用$ belongsToMany关系。

$ belongsTo表示您的模型与您的食谱模型的单个实体链接。

答案 1 :(得分:0)

要做到这一点,你需要选择" belongsToMany"关系。例如: 在你的模型中 'related_recipes' => [ 'Qdata\Taeq\Models\Recipe', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], 在相关的另一个模型 'makers' => [ 'Qdata\Taeq\Models\AnotherModel', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], 这会将多选下拉数据保存在数据库的相关数据透视表中。