Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Eloquent Power Joins

Eloquent Power Joins Laravel Package

kirschbaum-development/eloquent-power-joins

Eloquent Power Joins brings Laravel-style joins to Eloquent. Join via relationship definitions, reuse model scopes in join contexts, query relationship existence with joins, and sort by related columns/aggregations—all with cleaner, more readable queries.

View on GitHub
Deep Wiki
Context7

The Laravel magic applied to joins.

Frequently asked questions about Eloquent Power Joins
How do I join tables using Eloquent relationships instead of raw SQL in Laravel?
Use `joinRelationship('posts')` on your Eloquent query to join via the defined relationship. For example, `User::joinRelationship('posts')->get()` replaces manual `join('posts', 'posts.user_id', '=', 'users.id')` calls. The package automatically resolves foreign keys from your model definitions.
Can I use model scopes inside join conditions with this package?
Yes, you can apply scopes to joined tables using `joinRelationship('posts')->whereScope('published')`. This lets you reuse existing scopes (e.g., `published`, `active`) directly in join contexts, keeping your query logic DRY.
Does Eloquent Power Joins support Laravel 13? What about older versions?
The package officially supports Laravel 11–13. For Laravel 8–10, use version `3.*`, and for Laravel <8, use `2.*`. Check the [GitHub releases](https://github.com/kirschbaum-development/eloquent-power-joins/releases) for version-specific branches.
How does `powerJoinHas` differ from native `whereHas` in terms of performance?
`powerJoinHas` uses joins instead of subqueries (like `whereHas`), which can improve performance for large datasets by avoiding nested queries. However, benchmark your specific use case—deeply nested relationships might still favor `whereHas` for readability.
Can I sort results by columns from joined tables (e.g., `posts.created_at`)?
Yes, use `orderByPowerJoins('posts.created_at', 'desc')` to sort by related table columns. You can also sort by aggregations like `orderByPowerJoins('AVG(comments.rating)')` for complex ordering.
How do I handle many-to-many relationships with custom pivot tables?
Use `joinRelationship('roles', 'role_user')` to specify the pivot table name. For example, `User::joinRelationship('roles', 'role_user')->get()` will join via the `role_user` pivot table. Complex pivot conditions can be added via `joinRelationship()->wherePivot()`.
Will this package break existing queries if I add it to a Laravel project?
No, the package is backward-compatible. Existing `join()` or `whereHas` queries will continue working unchanged. You can incrementally replace them with `joinRelationship()` or `powerJoinHas()` methods.
How do I test queries using `joinRelationship` to ensure they match native SQL results?
Compare SQL output using Laravel Debugbar or `DB::enableQueryLog()`. Write unit tests with assertions like `assertEquals(expectedSQL, $query->toSql())` to verify join logic. For edge cases, test with soft-deleted models and polymorphic relationships.
Are there performance trade-offs when using joins vs. `whereExists` for checking relationship existence?
Joins (`powerJoinHas`) can be faster for large datasets than `whereExists` subqueries, but they may generate different execution plans. Test both approaches in your staging environment to identify the best fit for your query patterns.
What alternatives exist for cleaner joins in Laravel, and why choose this package?
Alternatives include raw SQL, query builder macros, or packages like `spatie/laravel-query-builder`. This package stands out by integrating natively with Eloquent relationships, scopes, and Laravel’s conventions—reducing boilerplate while keeping queries expressive and maintainable.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai