Skip to content

Commit

Permalink
refactor the basefilter
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Dec 9, 2023
1 parent b7844f0 commit 32e9988
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/BaseFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ abstract class BaseFilter
*/
protected const WILD_BOTH = 2;

protected Model $model;
private Model $model;

protected QueryBuilder $builder;

abstract protected function getModelClass(): string;

abstract public function applyFilter(array $queryParams): QueryBuilder;

protected function getModel(): Model
{
if (! isset($this->model)) {
$this->model = app($this->getModelClass());
}

return $this->model;
}

protected function whereLike(string $field, string $value, int $type): self
{
if ($value === '') {
Expand Down Expand Up @@ -82,7 +93,7 @@ public function setQuery(QueryBuilder $builder): void
protected function getQuery(): QueryBuilder
{
if (! isset($this->builder)) {
$this->builder = $this->model->query();
$this->builder = $this->getModel()->newQuery();
}

return $this->builder;
Expand Down

0 comments on commit 32e9988

Please sign in to comment.