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.Commentmodel belongs to either aPostOR aVideoviacommentable_idandcommentable_type).