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

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

Articles that may also be helpful: