https://github.com/kitloong/eloquent-power-joins-with-compoships
Use eloquent joins in Laravel way, with composite key support.
https://github.com/kitloong/eloquent-power-joins-with-compoships
composite-keys joint-models laravel-eloquent-models
Last synced: 6 months ago
JSON representation
Use eloquent joins in Laravel way, with composite key support.
- Host: GitHub
- URL: https://github.com/kitloong/eloquent-power-joins-with-compoships
- Owner: kitloong
- License: mit
- Created: 2021-09-03T15:53:58.000Z (almost 4 years ago)
- Default Branch: 1.x
- Last Pushed: 2024-07-02T05:52:05.000Z (12 months ago)
- Last Synced: 2024-12-26T16:08:48.752Z (6 months ago)
- Topics: composite-keys, joint-models, laravel-eloquent-models
- Language: PHP
- Homepage: https://kitloong.medium.com/laravel-eloquent-join-with-composite-keys-40a53a4e2dcc
- Size: 25.4 KB
- Stars: 23
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# Eloquent Power Joins with Compoships Support
This package is an [Eloquent Power Joins](https://github.com/kirschbaum-development/eloquent-power-joins) extension to support [Compoships](https://github.com/topclaudy/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. belongsToYou could read the detail explanation at [here](https://kitloong.medium.com/laravel-eloquent-join-with-composite-keys-40a53a4e2dcc).
## Installation
You can install the package via composer:
```
composer require kitloong/eloquent-power-joins-with-compoships
```## Usage
To implement join with composite key
```sql
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.
```php
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
```php
User::joinRelationship('posts');
```## License
This package is open-sourced software licensed under the [MIT license](LICENSE)