Tree structured models
Tree structuring covers the many to one relation, where one record can hold further sub-records. Editing the parent record in the administration shows a nested form for managing the records attached to it.

$belongsToModel parameter defines the relationship between two or more admin models.
app/OrdersItem.php
Foreign keys between the tables are created automatically.
Relations in a field
In other cases two independent modules need to be linked, where each model lives in a separate place in the administration with no tree structure between them. This kind of relation is created through fields, where a record is linked to a record in another table through a dropdown. ThebelongsTo and belongsToMany parameters link the record to one or several records at once.
One to one / Many to one
A record from another table is assigned to the parent record. Since several parent records can point to the same related record, this is a many to one relation.app/Article.php

Many to many
app/Article.php

For a many to many relation, CrudAdmin creates the pivot table automatically.
Relation settings
Filtering records in a field
filterBy filters the options of the current list based on the value of another field.
The first argument of
filterBy is the key of the form field to filter by (author). The second is the database column in the filtered table (articles). If the field name in the admin model does not match the database column name, the second argument is required — filterBy:author,author_id.Prefilling values from a relation
fillBy prefills a static value in the form from the selected related record.
author field.
Adding records from a field
Both belongsTo and belongsToMany fields can allow inserting records into the related table directly from the field, through thecanAdd parameter.

Clicking the add icon opens a modal window for creating the related record.
Selecting related records
Laravel requires relationship methods on the model to select related records. CrudAdmin automates this by mapping models to each other based on the fields and the tree structure. 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. The order module, holding the list of ordered products:app/Order.php
app/OrdersItem.php
Selecting a relation assigned in a field
The authors module, where each author is assigned to an article:app/Author.php
app/Tag.php
app/Article.php