📙
QuickAdminPanel
  • QuickAdminPanel Docs
  • Quick Start: Creating Panel
    • Creating a Simple CRUD
    • Radio/Checkbox/Select Fields
    • Relationships fields: belongsTo/belongsToMany
    • File/Photo Upload Fields
    • Date/Time Picker Fields
    • Multi-language Projects
    • API Generator
    • Roles and Permissions
    • How to Change Design Template/Theme
  • Using the Generated Code
    • Download Code and Install on Your Web-Server
    • Push Code to Your Github
    • Edit Code and Merge Changes
    • What Files are Inside the CRUD
  • Modules
    • Modules Overview
    • AJAX Datatables
    • System Calendar
    • Audit Changes Logs
    • Dashboard and Reports
    • Multi-Tenancy
    • CSV Import
    • Global Search
    • User Registration
    • Internal Messages
    • Change Notifications
    • Tasks + Calendar
    • Courses LMS
    • CRUD Templates Modules
  • Customizing the Code
    • Datatables Customizations
    • Upgrade Laravel version
    • Dependent Dropdowns: Parent-Child
    • Add Front User Without Admin Permissions
    • How to Add Mass Actions to Datatable
  • Vue.js + Laravel API Version
    • QuickAdminPanel: Vue.js+Laravel Version
    • What Files are Inside Vue.js+Laravel CRUD?
    • Installing Downloaded Vue.js+Laravel Panel
  • Livewire + Tailwind Version
    • QuickAdminPanel: Livewire+Tailwind Version
    • What Files are Inside Livewire+Tailwind CRUD?
    • Installing Downloaded Livewire+Tailwind Panel
Powered by GitBook
On this page
  • Showing Related Children Records on Parent's Page
  • Video Demo of Relationships
  • BelongsTo Relationship to Itself: The Same CRUD
  • Customizations of Relationships
  1. Quick Start: Creating Panel

Relationships fields: belongsTo/belongsToMany

PreviousRadio/Checkbox/Select FieldsNextFile/Photo Upload Fields

Last updated 4 years ago

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:

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.

If you tick that checkbox, then on the View page of the Parent's CRUD you will see a table of children's record:

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:

Master-Detail Form in Laravel + jQuery: Create Order With Products
Laravel BelongsTo and BelongsToMany with Same Table: Possible? Worth it?
One-To-Many with Soft-Deletes. Deleting Parent: Restrict or Cascade?
Customization: How to Make Two Dependent Dropdowns, like Parent-Child?
Laravel BelongsToMany: Add Extra Fields to Pivot Table
This will automatically generate column vehicles.owner_id with foreign key to users table
This will automatically generate role_user pivot table
You click "View" on parent's record
And it will show children records at the bottom