kitloong/eloquent-power-joins-with-compoships

The Laravel magic applied to joins, with compoships support
17,389 26
Install
composer require kitloong/eloquent-power-joins-with-compoships
Latest Version:v2.0.0
License:MIT
Last Updated:Sep 22, 2025
Links: GitHub  ·  Packagist
Maintainer: kitloong

Eloquent Power Joins with Compoships Support

This package is an Eloquent Power Joins extension to support Compoships.

You can now use joins in Laravel way, with composite key support.

This package support composite keys for relation:

  1. hasOne
  2. HasMany
  3. belongsTo

You could read the detail explanation at here.

Installation

You can install the package via composer:

composer require kitloong/eloquent-power-joins-with-compoships

Usage

To implement join with composite key

select users.* from users inner join posts on users.team_id = posts.team_id and users.category_id = posts.category_id;

First, you need to define the model relationship the way Compoships did.

use Awobaz\Compoships\Compoships;
use Kirschbaum\PowerJoins\PowerJoins;

class User extends Model
{
    use PowerJoins;
    use Compoships;
    
    public function posts()
    {
        return $this->hasMany(
            Post::class, 
            ['team_id', 'category_id'], 
            ['team_id', 'category_id']
        );
    }
}

Then you can get the same result by simply write

User::joinRelationship('posts');

License

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

Related Packages

kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

36,073,471 1,571
offworks/laraquent

An out of Laravel Eloquent 5.1 extended use, and as a provider to different micr...

45 1
phoenixgao/laravel-postgres-extended-schema

Laravel database schema extended, added some PostgreSql features

2,249 6
sleeping-owl/with-join

Package to convert Eloquent BelongsTo subqueries into one query with left join.

89,736 92