Created
November 17, 2018 14:49
-
-
Save stephandesouza/f431b5079dffd01783b78b7cdd105fa7 to your computer and use it in GitHub Desktop.
Extending RequestCriteria to add withCount parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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