What are Eloquent Relationships in Laravel?
Why Interviewers Ask This
This tests whether you can apply Laravel knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
Eloquent provides several relationship types for defining how models relate to each other. One-to-One: hasOne() / belongsTo(). One-to-Many: hasMany() / belongsTo(). Many-to-Many: belongsToMany() — requires a pivot table. Has Many Through: hasManyThrough() (access distant relations via an intermediate model). Polymorphic: morphTo() / morphMany() — a model belongs to multiple types. Access relations as properties (lazy loaded): $user->posts. Or as methods for chaining: $user->posts()->where("published", true)->get(). Each relationship method returns a query builder, enabling further constraints. Define foreign keys explicitly: hasMany(Post::class, "author_id", "id").
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Laravel project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is Tinker in Laravel?
Next
What is the N+1 problem and how does eager loading solve it?