0
votes

I am making a plugin on October CMS builder. Created couple db tables, models and forms in backend. Now trying to add form element (checkboxes) and want to make checkbox values to be taken from other table.

Example:

Table 1: categories
Model: Categories (relates to table categories)
Columns: id(INT, AI), name(VARCHAR), types(TEXT)

Table 2: types
Model: Types (relates to table types)
Columns: id(INT, AI), type(INT)

So in category creation form i want to assign types. For example:

Category name: News
Types: 1, 3, 7 (from table: types column: type)

How do i make this work?

2
October makes use of eloquent for models. Pretty well documented here: laravel.com/docs/5.1/eloquent-relationshipsDevon

2 Answers

1
votes

Simple you have to define a function called getTypesOptions in your model after creating the field in your fields.yaml file.

public function getTypesOptions()
{
    return \Namespace\Plugin\Models\Model::all();
}

And OctoberCMS is smart enough to handle everything else.

0
votes

Ok i found it. Lookep up in Rainlab plugin for relations and options.

In my Category model i have added a function to fetch required data from other table and it worked.

public function getTypesOptions()
{

}