Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

heyIm's avatar
Level 1

When to use relationship and when to joins for fetch data in laravel ?

I have little bit confusion between when to use relationship and when use joins for fetch data in laravel because both features results are same on such situations?

0 likes
3 replies
Cronix's avatar
Cronix
Best Answer
Level 67

I rarely use joins and mostly use relationships. Joins are great as they can execute a single query across multiple tables, however they are often more complex queries than relationships produce. So often, it's faster and more efficient to run multiple simple queries than one larger complex one.

3 likes
tykus's avatar

because both features results are same on such situations

This is incorrect.

Eloquent relations will result in additional queries, with related models nested as properties of the parent (in the context of the relationship) Eloquent model. Whenever you join, you are no longer working with discreet models. Aside from joins which aggregate some column(s) of a related table (sum, avg etc) or joins which get an attribute of what would otherwise be a hasOne/belongsTo related table, I tend to avoid using joins when I specifically want to work with models.

1 like
cmdobueno's avatar

This will be an extremely divided issue. I personally have little use for joins, not to say I never use them, I just use them extremely sparingly.

The use case scenarios are dependent on your code, as most things in laravel.

1 like

Please or to participate in this conversation.