Skip to content

Commit

Permalink
Add withCount method to Criteria (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephandesouza authored and bsormagec committed Dec 21, 2019
1 parent 65b5fa2 commit 684c46a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Prettus/Repository/Criteria/RequestCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function apply($model, RepositoryInterface $repository)
$orderBy = $this->request->get(config('repository.criteria.params.orderBy', 'orderBy'), null);
$sortedBy = $this->request->get(config('repository.criteria.params.sortedBy', 'sortedBy'), 'asc');
$with = $this->request->get(config('repository.criteria.params.with', 'with'), null);
$withCount = $this->request->get(config('repository.criteria.params.withCount', 'withCount'), null);
$searchJoin = $this->request->get(config('repository.criteria.params.searchJoin', 'searchJoin'), null);
$sortedBy = !empty($sortedBy) ? $sortedBy : 'asc';

Expand Down Expand Up @@ -163,6 +164,11 @@ public function apply($model, RepositoryInterface $repository)
$model = $model->with($with);
}

if ($withCount) {
$withCount = explode(';', $withCount);
$model = $model->withCount($withCount);
}

return $model;
}

Expand Down

0 comments on commit 684c46a

Please sign in to comment.