Skip to content

Instantly share code, notes, and snippets.

@stephandesouza
Created November 17, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephandesouza/f431b5079dffd01783b78b7cdd105fa7 to your computer and use it in GitHub Desktop.
Save stephandesouza/f431b5079dffd01783b78b7cdd105fa7 to your computer and use it in GitHub Desktop.
Extending RequestCriteria to add withCount parameter
<?php
namespace App\ModelRepositories\Criteria;
use Prettus\Repository\Contracts\RepositoryInterface;
use Prettus\Repository\Criteria\RequestCriteria as BaseRequestCriteria;
class RequestCriteria extends BaseRequestCriteria
{
/**
* {@inheritdoc}
*/
public function apply($model, RepositoryInterface $repository)
{
$model = parent::apply($model, $repository);
$withCount = $this->request->get(config('repository.criteria.params.withCount', 'withCount'), null);
if ($withCount) {
$withCount = explode(';', $withCount);
$model = $model->withCount($withCount);
}
return $model;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment