CommonWithCriteria.php 734 B

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