kitloong/eloquent-power-joins-with-compoships
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:
You could read the detail explanation at here.
You can install the package via composer:
composer require kitloong/eloquent-power-joins-with-compoships
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');
This package is open-sourced software licensed under the MIT license
How can I help you explore Laravel packages today?