1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Repositories\Criteria\Course;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class CourseChapterCriteria.
- *
- * @package namespace App\Repositories\Criteria;
- */
- class ChapterCriteria implements CriteriaInterface
- {
- public function __construct(Request $request = null)
- {
- if (is_null($request)) {
- $this->request = \request();
- } else {
- $this->request = $request;
- }
- }
- /**
- * Apply criteria in query repository
- *
- * @param string $model
- * @param RepositoryInterface $repository
- *
- * @return mixed
- */
- public function apply($model, RepositoryInterface $repository)
- {
- if ($title = $this->request->get('title')) {
- $model = $model->where('title', 'like', "%{$title}%");
- }
- if (($status = $this->request->get('status', false)) !== false) {
- $model = $model->where('status', '=', $status);
- }
- if ($course_id = $this->request->get('course_id')) {
- $model = $model->where('course_id', '=', $course_id);
- }
- $model = $model->orderByDesc('sort')->orderBy('id');
- return $model;
- }
- }
|