staudenmeir/eloquent-has-many-deep
Laravel Eloquent extension for “deep” has-many-through relationships across unlimited intermediate models. Supports many-to-many and polymorphic paths, combinations, and some third-party packages. Define relations by concatenating existing ones or configuring keys manually.
Country → User → Post → Comment) without manual query chaining, reducing boilerplate and improving maintainability.Category → Article → Section → Comment).Brand → Product → Review → Reply).Account → Project → Task → Log).User → Post/Video → Comment).Adopt When:
hasManyThrough chaining is cumbersome).User → Role → Permission).compoships, laravel-adjacency-list) are already in your stack.Look Elsewhere If:
hasManyThrough suffices).For Executives:
"This package lets us model complex data relationships—like a country’s users’ posts’ comments—in a single query, cutting development time and API complexity. For example, instead of writing 3 nested queries or manual joins, we define a hasManyDeep relationship once. This aligns with our goal to [reduce tech debt/build scalable features faster] while keeping costs low (MIT license, no vendor lock-in)."
For Engineering:
"This replaces verbose hasManyThrough chains with a first-class hasManyDeep method, supporting polymorphic, many-to-many, and custom-key relationships out of the box. It integrates with existing Laravel conventions and third-party packages like compoships, so adoption is low-risk. The package is actively maintained (recent 2026 releases) and includes IDE helpers for better developer experience. Tradeoff: Slightly more complex queries under the hood, but benchmarks show acceptable performance for most use cases."
How can I help you explore Laravel packages today?