kitloong/eloquent-power-joins-with-compoships

The Laravel magic applied to joins, with compoships support

Maintainers

👁 kitloong

Package info

github.com/kitloong/eloquent-power-joins-with-compoships

pkg:composer/kitloong/eloquent-power-joins-with-compoships

Fund package maintenance!

www.buymeacoffee.com/kitloong

Statistics

Installs: 16 998

Dependents: 0

Suggesters: 0

Stars: 26

Open Issues: 0

v2.0.0 2025-09-22 14:56 UTC

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT e5024ae57f80c5d3e4de98bc2b575ae8e8e7d390

  • Kit Loong <kitloong1008.woop@gmail.com>

mysqllaraveljoineloquent

This package is auto-updated.

Last update: 2026-06-22 16:48:10 UTC


README

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