Skip to content

Commit 995f39d

Browse files
committed
Initial commit
0 parents  commit 995f39d

39 files changed

+2324
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.editorconfig export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/phpcs.xml export-ignore
9+
/phpunit.xml export-ignore
10+
/tests export-ignore

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
custom: ['https://www.buymeacoffee.com/kitloong']

.github/workflows/check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: "Style check"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
check:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
- name: Setup PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 8.0
22+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, memcached
23+
tools: composer:v2
24+
coverage: none
25+
26+
- name: Install dependencies
27+
run: composer install --prefer-dist --no-interaction
28+
29+
- name: phpcs
30+
run: vendor/bin/phpcs

.github/workflows/tests.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "Run tests"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
test:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
php: [ 7.3, 7.4 ]
17+
laravel: [ 6.*, 7.*, 8.* ]
18+
include:
19+
- laravel: 8.*
20+
testbench: 6.*
21+
- laravel: 7.*
22+
testbench: 5.*
23+
- laravel: 6.*
24+
testbench: 4.*
25+
26+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v1
31+
32+
- name: Install SQLite 3
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install sqlite3
36+
37+
- name: Cache dependencies
38+
uses: actions/cache@v1
39+
with:
40+
path: ~/.composer/cache/files
41+
key: dependencies-pw-v2-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
42+
43+
- name: Setup PHP
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php }}
47+
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
48+
coverage: none
49+
tools: composer:v1
50+
51+
- name: Install dependencies
52+
run: |
53+
composer --version
54+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
55+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
56+
composer dump
57+
58+
- name: Execute tests
59+
run: vendor/bin/phpunit

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
vendor
3+
build
4+
composer.lock
5+
.phpunit.result.cache

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Kit Loong Liow
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Eloquent Power Joins with Compoships Support
2+
3+
This package is an [Eloquent Power Joins](https://github.com/kirschbaum-development/eloquent-power-joins) extension to support [Compoships](https://github.com/topclaudy/compoships).
4+
5+
You can now use joins in Laravel way, with composite key support.
6+
7+
This package support composite keys for relation:
8+
9+
1. hasOne
10+
2. HasMany
11+
3. belongsTo
12+
13+
## Installation
14+
15+
You can install the package via composer:
16+
17+
```
18+
composer require kitloong/eloquent-power-joins-with-compoships
19+
```
20+
21+
## Usage
22+
23+
To implement join with composite key
24+
25+
```sql
26+
select users.* from users inner join posts on users.team_id = posts.team_id and users.category_id = posts.category_id;
27+
```
28+
29+
First, you need to define the model relationship the way Compoships did.
30+
31+
```php
32+
use Awobaz\Compoships\Compoships;
33+
use KitLoong\PowerJoins\PowerJoins;
34+
35+
class User extends Model
36+
{
37+
use PowerJoins;
38+
use Compoships;
39+
40+
public function posts()
41+
{
42+
return $this->hasMany(
43+
Post::class,
44+
['team_id', 'category_id'],
45+
['team_id', 'category_id']
46+
);
47+
}
48+
}
49+
```
50+
51+
Then you can get the same result by simply write
52+
53+
```php
54+
User::joinRelationship('posts');
55+
```
56+
57+
## License
58+
59+
This package is open-sourced software licensed under the [MIT license](LICENSE)

composer.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "kitloong/eloquent-power-joins-with-compoships",
3+
"description": "The Laravel magic applied to joins, with compoships support",
4+
"keywords": [
5+
"laravel",
6+
"eloquent",
7+
"mysql",
8+
"join"
9+
],
10+
"license": "MIT",
11+
"type": "library",
12+
"authors": [
13+
{
14+
"name": "Kit Loong",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"kirschbaum-development/eloquent-power-joins": "^2.4",
20+
"awobaz/compoships": "^2.1"
21+
},
22+
"require-dev": {
23+
"orchestra/testbench": "4.*|5.*|6.*",
24+
"phpunit/phpunit": "^8.0",
25+
"laravel/legacy-factories": "^1.1",
26+
"squizlabs/php_codesniffer": "^3.6"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"KitLoong\\PowerJoins\\": "src"
31+
}
32+
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"KitLoong\\PowerJoins\\Tests\\": "tests"
36+
}
37+
},
38+
"extra": {
39+
"laravel": {
40+
"providers": [
41+
"KitLoong\\PowerJoins\\PowerJoinsServiceProvider"
42+
]
43+
}
44+
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true
47+
}

phpcs.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="eloquent-power-joins-with-compoships">
3+
<rule ref="PSR2">
4+
<exclude name="Generic.Files.LineLength"/>
5+
</rule>
6+
7+
<file>src</file>
8+
9+
<exclude-pattern>tests/KitLoong/database/*/*.php</exclude-pattern>
10+
</ruleset>

0 commit comments

Comments
 (0)