CommonWithCriteria.php 762 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * 通用With.
  4. *
  5. * @author jim <jim458734573@gmail.com>
  6. * @date 2020-01-30 09:52:38
  7. */
  8. declare(strict_types=1);
  9. namespace App\Repositories\Criterias;
  10. use Hyperf\Database\Query\Builder;
  11. use KZ2\Repositories\Contracts\RepositoryInterface;
  12. use KZ2\Repositories\Criteria\Criteria;
  13. class CommonWithCriteria extends Criteria
  14. {
  15. private $withParams = [];
  16. public function __construct($withParams)
  17. {
  18. $this->withParams = $withParams;
  19. }
  20. /**
  21. * @param Builder $model
  22. * @param RepositoryInterface $repository
  23. * @return mixed|void
  24. */
  25. public function apply(
  26. $model,
  27. RepositoryInterface $repository
  28. ) {
  29. $model = $model->with($this->withParams);
  30. return $model;
  31. }
  32. }