diff --git a/src/BaseEloquentRepository.php b/src/BaseEloquentRepository.php index 5dcd07c..1957147 100644 --- a/src/BaseEloquentRepository.php +++ b/src/BaseEloquentRepository.php @@ -50,7 +50,7 @@ protected function getDisplayField(): string /** * {@inheritDoc} */ - public function findOne(int|string $primaryKey = null): ?Model + public function findOne(int|string|null $primaryKey = null): ?Model { if (func_num_args() > 0) { $this->applyConditions(['id' => $primaryKey]); @@ -68,7 +68,7 @@ public function findOne(int|string $primaryKey = null): ?Model /** * {@inheritDoc} */ - public function findOneOrFail(int|string $primaryKey = null): Model + public function findOneOrFail(int|string|null $primaryKey = null): Model { if (func_num_args() > 0) { $this->applyConditions(['id' => $primaryKey]); @@ -116,7 +116,7 @@ public function findAll(array $options = []): EloquentCollection /** * {@inheritDoc} */ - public function findList(string $key = null, string $value = null): Collection + public function findList(?string $key = null, ?string $value = null): Collection { $this->applyCriteria(); $this->applyRelations(); @@ -138,7 +138,7 @@ public function findList(string $key = null, string $value = null): Collection /** * {@inheritDoc} */ - public function paginate(int $perPage = null): Paginator + public function paginate(?int $perPage = null): Paginator { $perPage = $this->preparePageSize($perPage); @@ -156,7 +156,7 @@ public function paginate(int $perPage = null): Paginator * * @throws \InvalidArgumentException */ - protected function preparePageSize(int $perPage = null): int + protected function preparePageSize(?int $perPage = null): int { if ($perPage <= 0) { throw new InvalidArgumentException('Invalid page size'); diff --git a/src/Contracts/RepositoryInterface.php b/src/Contracts/RepositoryInterface.php index 84567d9..016b4ce 100644 --- a/src/Contracts/RepositoryInterface.php +++ b/src/Contracts/RepositoryInterface.php @@ -13,14 +13,14 @@ interface RepositoryInterface * It applies the conditions, criteria, relations, and order by to the query, * then gets the first result and resets the query */ - public function findOne(int|string $primaryKey = null): ?Model; + public function findOne(int|string|null $primaryKey = null): ?Model; /** * If the result of the `findOne` function is null, throw a `ModelNotFoundException` * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException */ - public function findOneOrFail(int|string $primaryKey = null): Model; + public function findOneOrFail(int|string|null $primaryKey = null): Model; /** * It takes an array of options, applies them to the query, executes the query, and returns the results. @@ -36,12 +36,12 @@ public function findAll(array $options = []): EloquentCollection; * @param string|null $value The field to use as the value of the select list. * @return \Illuminate\Support\Collection A collection of key value pairs. */ - public function findList(string $key = null, string $value = null): Collection; + public function findList(?string $key = null, ?string $value = null): Collection; /** * It applies the criteria, relations, and order by to the query, then paginates the results and resets the query */ - public function paginate(int $perPage = null): Paginator; + public function paginate(?int $perPage = null): Paginator; /** * Add a criteria to the query. diff --git a/src/Contracts/SearchableRepositoryInterface.php b/src/Contracts/SearchableRepositoryInterface.php index 020673d..01db2d4 100644 --- a/src/Contracts/SearchableRepositoryInterface.php +++ b/src/Contracts/SearchableRepositoryInterface.php @@ -9,5 +9,5 @@ interface SearchableRepositoryInterface /** * Search for records based on the provided query parameters and paginate the results. */ - public function search(array $queryParams, int $perPage = null): Paginator; + public function search(array $queryParams, ?int $perPage = null): Paginator; } diff --git a/src/Traits/Searchable.php b/src/Traits/Searchable.php index b82c169..9ab41b0 100644 --- a/src/Traits/Searchable.php +++ b/src/Traits/Searchable.php @@ -12,7 +12,7 @@ trait Searchable { abstract protected function getFilterManager(): BaseFilter; - public function search(array $queryParams, int $perPage = null): Paginator + public function search(array $queryParams, ?int $perPage = null): Paginator { $this->setQuery($this->getFilterManager()->applyFilter($queryParams));