【问题标题】:How to add multi select value in database in October CMS Backend?如何在十月 CMS 后端的数据库中添加多选值?
【发布时间】:2016-06-14 10:38:22
【问题描述】:

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

我的 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'
                      ],

                 ];

目前只有一个选定的值插入到数据库中。需要在数据库中添加多个值。有没有人能解决的?

【问题讨论】:

标签: laravel-5 octobercms


【解决方案1】:

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

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

【讨论】:

  • 我已经检查了 $belongsToMany 但不适合我。谢谢
【解决方案2】:

要使用关系,您需要使用“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', ], 这会将您的多选下拉数据保存在数据库的相关数据透视表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多