1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Repositories\Criteria\Dwbs;
- use App\Repositories\Enums\ModelStatusEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class BusinessSchoolCriteria 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('type')) {
- $val = $this->request->get('type');
- $model = $model->where('type', '=', $val);
- }
- if ($this->request->filled('day')) {
- $val = $this->request->get('day');
- $model = $model->where('day', '=', $val);
- }
- if ($this->request->filled('category_id')) {
- $val = $this->request->get('category_id');
- if ($val) $model = $model->where('category_id', '=', $val);
- }
- if ($this->request->filled('name')) {
- $val = $this->request->get('name');
- $model = $model->where('name', 'like', "%{$val}%");
- }
- if ($this->request->filled('status')) {
- $status = $this->request->get('status');
- $model = $model->where('status', '=', $status);
- }
- 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 (!isAdminModule()) $model = $model->where('status', ModelStatusEnum::OK);
- return $model;
- }
- }
|