1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Repositories\Criteria\School;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- /**
- * Class LessonCriteria.
- *
- * @package namespace App\Repositories\Criteria\School;
- */
- class LessonCriteria implements CriteriaInterface
- {
- private $request;
- 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 ($this->request->filled('name')) {
- $name = $this->request->get('name');
- $model = $model->where('name', 'like', "%{$name}%");
- }
- if ($this->request->filled('term_id')) {
- $term_id = $this->request->get('term_id');
- $model = $model->where('term_id', '=', $term_id);
- }
- if ($this->request->filled('category_id')) {
- $category_id = $this->request->get('category_id');
- $model = $model->where('category_id', '=', $category_id);
- }
- if ($this->request->filled('teacher_id')) {
- $teacher_id = $this->request->get('teacher_id');
- $model = $model->where('teacher_id', '=', $teacher_id);
- }
- if ($this->request->filled('no')) {
- $no = $this->request->get('no');
- $model = $model->where('no', 'like', "%{$no}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- $model = $model->orderByDesc('id');
- return $model;
- }
- }
|