Relationships fields: belongsTo/belongsToMany
Last updated
Last updated
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:
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:
This is a quick video demo of both belongsTo and belongsToMany.
Quick video demo how you can create a relationship to itself, for parent-children "tree". For example, Category belongsTo Category with category_id field.
Articles that may also be helpful: