Relationships fields: belongsTo/belongsToMany

QuickAdminPanel supports two types of relationships between CRUDs:
  • One-to-Many: belongsTo() + hasMany()
  • Many-to-Many: belongsToMany().
To create a relationship, you just need to choose field type belongsTo or belongsToMany.
You don't need to manually create separate field or pivot table, they will be created automatically:
  • In case of belongsTo, QuickAdminPanel will automatically create DB column xxxxxx_id with a foreign key to the parent table.
  • In case of belongsToMany, QuickAdminPanel will automatically create a pivot table, you don't need to create that table manually.
Here are examples of filled-in forms for belongsTo and belongsToMany:
This will automatically generate column vehicles.owner_id with foreign key to users table
This will automatically generate role_user pivot table
One more feature: you can enable the children's records to be shown in a show() method page of a parent CRUD.
If you tick that checkbox, then on the View page of the Parent's CRUD you will see a table of children's record:
You click "View" on parent's record
And it will show children records at the bottom

Video Demo of Relationships

This is a quick video demo of both belongsTo and belongsToMany.

BelongsTo Relationship to Itself: The Same CRUD

Quick video demo how you can create a relationship to itself, for parent-children "tree". For example, Category belongsTo Category with category_id field.

Customizations of Relationships

Articles that may also be helpful: