I know how to do this using Eloquent, but I’m struggling to figure out how to achieve it using .yaml files in OctoberCMS. Could you guide me in the right direction?
What I’m trying to do is use the articles relationship I added to the users plugin on the backend user update page. When adding an article, there are several inputs that are not used in the articles table but should be included in the pivot table. I want to fill these inputs when adding an article and ensure that these data points are added to the user_article pivot relationship when the article data is saved.
Can you help me with this?
// Article relations ( UserModel::extend(…) )
$model->belongsToMany[‘articles’] = [
Article::class,
‘table’ => ‘foo_plugin_user_article’,
‘key’ => ‘user_id’,
‘otherKey’ => ‘article_id’,
‘pivot’ => [‘article_author_order’, ‘user_article_field’, ‘user_article_subfield’]
];
// config_relation.yaml
articles:
label: “Articles”
view:
list: $/foo/plugin/models/article/columns.yaml
toolbarButtons: add|remove|create|delete
manage:
list: $/foo/plugin/models/article/columns.yaml
form: $/foo/plugin/models/article/fields.yaml