Ashish Detroja
Ashish Detroja

Reputation: 1082

How to add multi select value in database in October CMS Backend?

enter image description here

Not inserted multi select value in database.

My fields.yaml Code is :

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

My model code is :

public $belongsTo = [

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

                 ];

Currently only one selected value inserted in database.need add multiple value in database. Can any one have the solution of it ?

Upvotes: 0

Views: 678

Answers (2)

Omar Faruk
Omar Faruk

Reputation: 399

To do so with relation you need to go with "belongsToMany" relation. for example: In your Model 'related_recipes' => [ 'Qdata\Taeq\Models\Recipe', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], In related another Model 'makers' => [ 'Qdata\Taeq\Models\AnotherModel', 'table' => 'pivot_table_name', 'key' => 'foreign_key_of_pivot_table', 'otherKey' => 'other_key', ], this will save your multiselect dropdown data in the related pivot table in your database.

Upvotes: 0

KerooZ
KerooZ

Reputation: 61

You should use a $belongsToMany relation in this case.

$belongsTo means your model is link with a single entity of your Recipe model.

Upvotes: 0

Related Questions