123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Repositories\Criteria\Course;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class CollectCriteria implements CriteriaInterface
- {
- /**
- * @var \Illuminate\Http\Request
- */
- protected $request;
- public function __construct(Request $request)
- {
- $this->request = $request;
- }
- /**
- * @param $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($this->request->filled('course_id')) {
- $val = $this->request->get('course_id');
- $model = $model->where('course_id', '=', $val);
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- if ($this->request->filled('user_id')) {
- $val = $this->request->get('user_id');
- $model = $model->where('user_id', '=', $val);
- }
- if ($this->request->filled('ids')) {
- $ids = $this->request->get('ids');
- $model = $model->whereIn('id', $ids);
- }
- if (!$this->request->filled('orderBy')) {
- $model = $model->orderByDesc('id');
- }
- if (isApiModule()) {
- $model = $model->where('user_id', login_user_id());
- }
- return $model;
- }
- }
|