Skip to content

How To Implement A Many To Many Relationship To Form (E.g : Film -> R <- Actors) ​

Films Table - films ​

Field NameData Type
idint(PK)
created_attimestamp
namevarchar(255)
descriptiontext

Actors Table - actors ​

Field NameData Type
idint(PK)
namevarchar(255)

Films Actors Table - films_actors ​

Field NameData Type
idint(PK)
films_idint(11)
actors_idint(11)

We need multiple select box, so we use select2 with datatable and relationship_table attribute

Code For Form of Films Controller ​

php
$this->form[] - ['label'=>'Name','type'=>'text','name'=>'name'];
$this->form[] = ['label'=>'Description','type'=>'textarea','name'=>'description'];
$this->form[] = ['label'=>'Actors','type'=>'select2','datatable'=>'actors,name','relationship_table'=>'films_actors'];

What's Next ​

Table Of Contents ​

Released under the MIT License.