From 301cec75f9f67c9fcd522c0d6c5196611e082924 Mon Sep 17 00:00:00 2001 From: Ben Sherred Date: Sat, 25 Nov 2023 18:14:22 +0000 Subject: [PATCH] feat: add whereSqidNotIn mixin --- ...eSqidsInMixin.php => WhereSqidInMixin.php} | 12 ++++++++--- src/Mixins/WhereSqidNotInMixin.php | 20 +++++++++++++++++++ src/SqidsServiceProvider.php | 6 ++++-- 3 files changed, 33 insertions(+), 5 deletions(-) rename src/Mixins/{WhereSqidsInMixin.php => WhereSqidInMixin.php} (57%) create mode 100644 src/Mixins/WhereSqidNotInMixin.php diff --git a/src/Mixins/WhereSqidsInMixin.php b/src/Mixins/WhereSqidInMixin.php similarity index 57% rename from src/Mixins/WhereSqidsInMixin.php rename to src/Mixins/WhereSqidInMixin.php index 0019fc8..bbc182a 100644 --- a/src/Mixins/WhereSqidsInMixin.php +++ b/src/Mixins/WhereSqidInMixin.php @@ -6,13 +6,19 @@ use Closure; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; /** @mixin Builder */ -class WhereSqidsInMixin +class WhereSqidInMixin { - public function whereSqidsIn(): Closure + public function whereSqidIn(): Closure { - return function (string $column, array $sqids, $boolean = 'and', $not = false) { + return function (array $sqids, $boolean = 'and', $not = false) { + /** @var Model $model */ + $model = $this->getModel(); + + $column = $model->qualifyColumn(column: $model->getKeyName()); + /** @phpstan-ignore-next-line */ $values = array_map(callback: fn(string $sqid) => $this->getModel()->keyFromSqid(sqid: $sqid), array: $sqids); diff --git a/src/Mixins/WhereSqidNotInMixin.php b/src/Mixins/WhereSqidNotInMixin.php new file mode 100644 index 0000000..9461a04 --- /dev/null +++ b/src/Mixins/WhereSqidNotInMixin.php @@ -0,0 +1,20 @@ +whereSqidIn(sqids: $sqids, boolean: $boolean, not: true); + }; + } +} diff --git a/src/SqidsServiceProvider.php b/src/SqidsServiceProvider.php index bd5c9a8..fffdee9 100644 --- a/src/SqidsServiceProvider.php +++ b/src/SqidsServiceProvider.php @@ -9,7 +9,8 @@ use RedExplosion\Sqids\Mixins\FindBySqidMixin; use RedExplosion\Sqids\Mixins\FindOrFailBySqidMixin; use RedExplosion\Sqids\Mixins\WhereSqidMixin; -use RedExplosion\Sqids\Mixins\WhereSqidsInMixin; +use RedExplosion\Sqids\Mixins\WhereSqidInMixin; +use RedExplosion\Sqids\Mixins\WhereSqidNotInMixin; class SqidsServiceProvider extends ServiceProvider { @@ -36,7 +37,8 @@ protected function bootBuilderMixins(): void { Builder::mixin(new FindBySqidMixin()); Builder::mixin(new FindOrFailBySqidMixin()); + Builder::mixin(new WhereSqidInMixin()); Builder::mixin(new WhereSqidMixin()); - Builder::mixin(new WhereSqidsInMixin()); + Builder::mixin(new WhereSqidNotInMixin()); } }