generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mr-punyapal/refactor
Refactor
- Loading branch information
Showing
12 changed files
with
122 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
// config for Mrpunyapal/LaravelExtendedRelationships | ||
return [ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"preset": "laravel", | ||
"rules": { | ||
"declare_strict_types": true, | ||
"strict_param":true, | ||
"strict_comparison":true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mrpunyapal\LaravelExtendedRelationships; | ||
|
||
use Illuminate\Contracts\Database\Query\Builder; | ||
use Mrpunyapal\LaravelExtendedRelationships\Relations\BelongsToArrayColumn; | ||
use Mrpunyapal\LaravelExtendedRelationships\Relations\BelongsToManyKeys; | ||
use Mrpunyapal\LaravelExtendedRelationships\Relations\HasManyArrayColumn; | ||
use Mrpunyapal\LaravelExtendedRelationships\Relations\HasManyKeys; | ||
|
||
trait HasExtendedRelationships | ||
{ | ||
/** | ||
* @param string|null $foreignKey | ||
* @param string[]|null $relations | ||
*/ | ||
public function belongsToManyKeys(string $related, string $foreignKey, array $relations): BelongsToManyKeys | ||
public function belongsToManyKeys(string $related, ?string $foreignKey, ?array $relations): BelongsToManyKeys | ||
{ | ||
$instance = new $related(); | ||
|
||
return new BelongsToManyKeys($instance->newQuery(), $this, $foreignKey, $relations); | ||
return new BelongsToManyKeys($this->relatedNewQuery($related), $this, $foreignKey, $relations); | ||
} | ||
|
||
/** | ||
* @param string[]|null $relations | ||
*/ | ||
public function hasManyKeys(string $related, ?array $relations = null, ?string $localKey = null): HasManyKeys | ||
public function hasManyKeys(string $related, ?array $relations, ?string $localKey): HasManyKeys | ||
{ | ||
$instance = new $related(); | ||
|
||
return new HasManyKeys($instance->newQuery(), $this, $relations, $localKey); | ||
return new HasManyKeys($this->relatedNewQuery($related), $this, $relations, $localKey); | ||
} | ||
|
||
public function hasManyArrayColumn(string $related, ?string $foreignKey, ?string $localKey): HasManyArrayColumn | ||
{ | ||
$instance = new $related(); | ||
|
||
return new HasManyArrayColumn($instance->newQuery(), $this, $foreignKey, $localKey); | ||
return new HasManyArrayColumn($this->relatedNewQuery($related), $this, $foreignKey, $localKey); | ||
} | ||
|
||
public function belongsToArrayColumn(string $related, ?string $foreignKey, ?string $localKey, $isString = false): BelongsToArrayColumn | ||
public function belongsToArrayColumn(string $related, ?string $foreignKey, ?string $localKey, bool $isString = false): BelongsToArrayColumn | ||
{ | ||
$instance = new $related(); | ||
return new BelongsToArrayColumn($this->relatedNewQuery($related), $this, $foreignKey, $localKey, null, $isString); | ||
} | ||
|
||
return new BelongsToArrayColumn($instance->newQuery(), $this, $foreignKey, $localKey, null, $isString); | ||
protected function relatedNewQuery($related): Builder | ||
{ | ||
return (new $related())->newQuery(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.