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 SQL joins, reducing backend complexity.User → Role → Permission → Module).Category → Product → Variant → Review).User → Post → Like → Comment).Adopt if:
hasManyThrough.compoships, laravel-adjacency-list) that integrate with this package.Look elsewhere if:
hasManyThrough or belongsTo.For Executives: "This package lets us model complex data relationships (e.g., user → post → comment → reply) with minimal code, reducing backend complexity and speeding up feature delivery. For example, we could build a nested comment system or role-permission hierarchy without writing custom SQL. It’s battle-tested, integrates with Laravel’s ecosystem, and saves dev time—ideal for scaling our [product area]."
For Engineering: *"This replaces manual SQL joins or recursive queries for deep relationships. Key benefits:
hasManyDeep in one line (e.g., Country → User → Post → Comment).compoships.where('posts.published', true)).HasManyDeep return type.
Tradeoff: Adds ~1MB to your vendor directory. Recommended for projects with multi-level data flows."*For Developers: *"Say goodbye to:
// Before: Manual joins
DB::table('countries')
->join('users', 'users.country_id', '=', 'countries.id')
->join('posts', 'posts.user_id', '=', 'users.id')
->join('comments', 'comments.post_id', '=', 'posts.id')
->where(...);
Now:
// After: hasManyDeep
$country->comments()->where('posts.published', true);
Supports constraints, soft deletes, and third-party packages like laravel-adjacency-list for trees/graphs."*
How can I help you explore Laravel packages today?