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), addressing a critical gap in native Laravel. This aligns well with hierarchical data models (e.g., organizational charts, nested comments, multi-tiered permissions).MorphMany, MorphToMany) and many-to-many relationships, making it versatile for complex schemas (e.g., tagging systems, dynamic role-permission models).laravel-adjacency-list (for trees/graphs) and compoships (composite keys), broadening use cases for non-standard relationships.use trait and method definition (e.g., hasManyDeep()), reducing migration effort.with), enabling seamless integration into existing query logic.select() to limit columns).toSql() are recommended.User → Role → Permission) to validate integration.hasManyThrough or manual joins.hasManyThrough with hasManyDeep for deeply nested models.hasManyDeep.Post::whereHas() chain into a single hasManyDeep call.hasManyThrough + hasMany), reducing refactoring.laravel-adjacency-list (for hierarchical data) and compoships (composite keys), enabling advanced use cases.withTrashed() and soft-deleted models out of the box.staudenmeir/eloquent-has-many-deep:^1.7).HasRelationships trait and define hasManyDeep/hasOneDeep methods.toSql() and benchmark performance.->toSql()). Consider adding logging for deep queries.latest_comment_id on Post).cursor() or simplePaginate() for large datasets.whereHas or constraints.with() or use load() for nested relationships.A → B → A). Validate schema design.exists() checks or transactions.hasManyDeep() and hasManyThrough().select() for deep queries).toSql() and dd().How can I help you explore Laravel packages today?