> For the complete documentation index, see [llms.txt](https://helpdocs.quickadminpanel.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://helpdocs.quickadminpanel.com/create-panel/relationship-fields-belongsto-belongstomany.md).

# Relationships fields: belongsTo/belongsToMany

QuickAdminPanel supports two types of relationships between CRUDs:&#x20;

* **One-to-Many:** belongsTo() + hasMany()
* **Many-to-Many:** belongsToMany().

To create a relationship, you just need to choose field type **belongsTo** or **belongsToMany.**

![](/files/-M7qHF8JNFo4Lstl8bCg)

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](/files/-M7qHcL8Cw_WlsFTLJbc)

![This will automatically generate role\_user pivot table](/files/-M7qHuaLlRSIeNA9cuk_)

## Showing Related Children Records on Parent's Page

One more feature: you can enable the children's records to be shown in a **show()** method page of a parent CRUD.

![](/files/-MAAsCwwKKJWlDhWVwMn)

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](/files/-MAAuiZTHu8Z71PodWow)

![And it will show children records at the bottom](/files/-MAAupLAYRTfW9Io_1zZ)

## Video Demo of Relationships

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

{% embed url="<https://www.youtube.com/watch?v=Txjzcz19d0s>" %}

## 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.

{% embed url="<https://www.youtube.com/watch?v=kn-0yZU5mZ8>" %}

## Customizations of Relationships&#x20;

Articles that may also be helpful:

* [Master-Detail Form in Laravel + jQuery: Create Order With Products](https://quickadminpanel.com/blog/master-detail-form-in-laravel-jquery-create-order-with-products/)
* [Laravel BelongsTo and BelongsToMany with Same Table: Possible? Worth it?](https://quickadminpanel.com/blog/belongsto-and-belongstomany-with-same-table-possible-worth-it/)
* [One-To-Many with Soft-Deletes. Deleting Parent: Restrict or Cascade?](https://quickadminpanel.com/blog/one-to-many-with-soft-deletes-deleting-parent-restrict-or-cascade/)
* [Customization: How to Make Two Dependent Dropdowns, like Parent-Child?](https://helpdocs.quickadminpanel.com/customizing-the-code/dependent-dropdowns-parent-child)
* [Laravel BelongsToMany: Add Extra Fields to Pivot Table](https://quickadminpanel.com/blog/laravel-belongstomany-add-extra-fields-to-pivot-table/)
