123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Repositories\Criteria\Base;
- use App\Repositories\Enums\Base\AdminTypeEnum;
- use Illuminate\Http\Request;
- use Prettus\Repository\Contracts\CriteriaInterface;
- use Prettus\Repository\Contracts\RepositoryInterface;
- class DepartmentCriteria 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('name')) {
- $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%');
- }
- if ($this->request->filled('status')) {
- $model = $model->where('status', '=', $this->request->get('status'));
- }
- if ($this->request->filled('type')) {
- $model = $model->where('type', '=', $this->request->get('type'));
- }
- if ($this->request->filled('parent_id')) {
- $model = $model->where('parent_id', '=', $this->request->get('parent_id'));
- }
- if ($this->request->filled('is_system')) {
- $model = $model->where('is_system', '=', $this->request->get('is_system'));
- }
- $admin = login_admin();
- switch ($admin['type']) {
- case AdminTypeEnum::ADMIN:
- $company_id = $admin['company_id'];
- if ($company_id) $model = $model->where('company_id', '=', $company_id);
- break;
- }
- return $model;
- }
- }
|