Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Eloquent Power Joins

kirschbaum-development/eloquent-power-joins image

Eloquent Power Joins stats

Downloads
1.7M
Stars
1,190
Open Issues
9
Forks
76

View on GitHub →

The Laravel magic applied to joins.

Eloquent Power Joins

Enhance your Laravel application with "Eloquent Power Joins", a powerful package designed to facilitate advanced join queries using Eloquent ORM in a more intuitive "Laravel way". This package simplifies the management of complex SQL joins, making your database interactions both cleaner and more efficient.

Features

  • Join Relationships Easily: Utilize existing Eloquent relationships to perform join queries without manually specifying the foreign keys or table names.
  • Scope and Condition Support: Apply local scopes and custom conditions directly within your join operations.
  • Nested and Polymorphic Joins: Supports complex nested joins and automatically handles polymorphic relationships.
  • Alias Handling: Use aliases effortlessly in your joins to avoid column name conflicts.
  • Enhanced Sorting: Sort query results based on related model columns and aggregates directly.
  • Query Relationship Existence: Use join operations instead of subqueries to check for the existence of relationships, enhancing performance.
  • Soft Deletes Awareness: Automatically accounts for soft deleted records in joins unless specified otherwise.
  • Global Scopes Compatibility: Integrate global scopes within your joins with ease.

Installation

Install via composer for Laravel versions 8 and above:

composer require kirschbaum-development/eloquent-power-joins

For Laravel versions below 8, use:

composer require kirschbaum-development/eloquent-power-joins:2.*

Usage

To use the power joins, include the PowerJoins trait in your Eloquent models:

use Kirschbaum\PowerJoins\PowerJoins;
 
class User extends Model
{
use PowerJoins;
}

Basic Join

User::joinRelationship('posts');

Nested and Polymorphic Joins

User::joinRelationship('posts.comments');
Post::joinRelationship('images'); // For polymorphic relationships

Applying Conditions

User::joinRelationship('posts', function ($join) {
$join->where('posts.approved', true);
});

Using Aliases

Post::joinRelationshipUsingAlias('category.parent', 'category_alias');

Checking Relationship Existence

User::powerJoinHas('posts.comments');

Ordering by Related Columns

User::orderByPowerJoins('profile.city');

Contributing

Contributions are welcome! Please refer to the contributing guidelines.

Security

For any security issues, contact luis@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com.

License

This package is open-sourced software licensed under the MIT license.

kirschbaum-development photo

We are a team of carefully curated Laravel experts with a history of delivering practical and efficient solutions to complex problems.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Kirschbaum Development Eloquent Power Joins Related Articles

Laravel IDEA v10 is Here image

Laravel IDEA v10 is Here

Read article
Laravel Eloquent Power Joins Package image

Laravel Eloquent Power Joins Package

Read article
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review