diff --git a/src/HasSqids.php b/src/HasSqids.php index 8089400..88a5268 100644 --- a/src/HasSqids.php +++ b/src/HasSqids.php @@ -23,22 +23,6 @@ public function getRouteKeyName(): string return 'sqid'; } - /** - * Retrieve the model for a bound value. - * - * @param mixed $value - * @param string|null $field - * @return Model|null - */ - // public function resolveRouteBinding($value, $field = null): ?Model - // { - // if ($field !== null) { - // return parent::resolveRouteBinding(value: $value, field: $field); - // } - // - // return $this->findBySqid($value); - // } - /** * Retrieve the model for a bound value. * diff --git a/src/Mixins/FindBySqidMixin.php b/src/Mixins/FindBySqidMixin.php index 6682088..d6ddee5 100644 --- a/src/Mixins/FindBySqidMixin.php +++ b/src/Mixins/FindBySqidMixin.php @@ -13,6 +13,6 @@ class FindBySqidMixin { public function findBySqid(): Closure { - return fn($id, $columns = ['*']) => $this->find(id: Sqids::decodeId(id: $id), columns: $columns); + return fn(string $id, array $columns = ['*']) => $this->find(id: Sqids::decodeId(id: $id), columns: $columns); } } diff --git a/src/Mixins/WhereSqidMixin.php b/src/Mixins/WhereSqidMixin.php index 40222ec..4c6fc83 100644 --- a/src/Mixins/WhereSqidMixin.php +++ b/src/Mixins/WhereSqidMixin.php @@ -13,6 +13,6 @@ class WhereSqidMixin { public function whereSqid(): Closure { - return fn($id) => $this->whereKey(id: Sqids::decodeId(id: $id)); + return fn(string $id) => $this->whereKey(id: Sqids::decodeId(id: $id)); } } diff --git a/src/Mixins/WhereSqidsInMixin.php b/src/Mixins/WhereSqidsInMixin.php new file mode 100644 index 0000000..2459bc5 --- /dev/null +++ b/src/Mixins/WhereSqidsInMixin.php @@ -0,0 +1,22 @@ + Sqids::decodeId(id: $sqid), array: $sqids); + + return $this->whereIn(column: $column, values: $values, boolean: $boolean, not: $not); + }; + } +} diff --git a/src/SqidsServiceProvider.php b/src/SqidsServiceProvider.php index 64e19a4..a27b9f3 100644 --- a/src/SqidsServiceProvider.php +++ b/src/SqidsServiceProvider.php @@ -8,6 +8,7 @@ use Illuminate\Support\ServiceProvider; use RedExplosion\Sqids\Mixins\FindBySqidMixin; use RedExplosion\Sqids\Mixins\WhereSqidMixin; +use RedExplosion\Sqids\Mixins\WhereSqidsInMixin; class SqidsServiceProvider extends ServiceProvider { @@ -34,5 +35,6 @@ protected function bootBuilderMixins(): void { Builder::mixin(new FindBySqidMixin()); Builder::mixin(new WhereSqidMixin()); + Builder::mixin(new WhereSqidsInMixin()); } }