CrudAdmin automates the relations between models. It designs the relational database, generates an interface that supports the relations, and binds the relation methods of the models.

Tree structured models

A child admin model is attached to its parent with $belongsToModel. The parent form then shows a nested module for the child records, and the foreign keys and relations are created automatically.
app/Models/OrdersItem.php
Parent models, recursive trees, children created before the parent and relations to any model are described in Tree, ordering and publishing.

Relations in a field

Two independent modules, each in its own place in the administration, are linked through fields. A record is linked to one record of another table with belongsTo, or to several records with belongsToMany.
app/Models/Article.php
Relation fields, their options, filters and buttons are described in Relation fields. Laravel requires relationship methods on the model to select related records. CrudAdmin maps the models to each other based on the fields and the tree structure, so you do not have to write these methods. Defining your own relations in the model is still possible when you need it.

Selecting a relation in a tree structure

This example works with an order that contains several ordered items.
app/Models/Order.php
The ordered item module, attached to a single order:
app/Models/OrdersItem.php
Selecting the items of an order:
Selecting the order of an item:

Selecting a relation assigned in a field

app/Models/Article.php
Relations are bound automatically as long as the relation fields are correct and the English plural is used for reverse relations.