Skip to main content
InterviewHubPRO
Section Overview
Q9

Question 9 of 50

Part 1: Architecture, Service Container & Request Lifecycle (1 - 10)

18%
Laravel & Ecosystem (50 Qs)•Part 1: Architecture, Service Container & Request Lifecycle (1 - 10)

What are Eloquent Relationships (One-to-Many, Many-to-Many, Polymorphic)?

senior LevelLifecycleDocker & ContainersSystem Design

In Simple Words:

  • One-to-Many (hasMany / belongsTo): User has many Posts.
  • Many-to-Many (belongsToMany): Users and Roles joined via an intermediate pivot table (role_user).
  • Polymorphic (morphTo / morphMany): A single target model can belong to multiple different parent models on a single table (e.g. Comment model belongs to either a Post OR a Video via commentable_id and commentable_type).