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('username')) { $model = $model->where('username', 'like', '%' . $this->request->get('username') . '%'); } if ($this->request->filled('mobile')) { $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile') . '%'); } if ($this->request->filled('email')) { $model = $model->where('email', 'like', '%' . $this->request->get('email') . '%'); } if ($this->request->filled('sex')) { $model = $model->where('sex', '=', $this->request->get('sex')); } if ($this->request->filled('department_id')) { $model = $model->where('department_id', '=', $this->request->get('department_id')); } 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('company_id')) { $model = $model->where('company_id', '=', $this->request->get('company_id')); } if ($this->request->filled('shop_id')) { $role_name = $this->request->get('role_name', false); $role_id = $this->request->get('role_id', false); if ($role_name == RoleEnum::COACH_CAR || $role_id == 4) { $model = $model->whereIn('shop_id', [0, $this->request->get('shop_id')]); } else { $model = $model->where('shop_id', '=', $this->request->get('shop_id')); } } if ($this->request->filled('is_view_user_info')) { $model = $model->where('is_view_user_info', '=', $this->request->get('is_view_user_info')); } if ($this->request->filled('role_name')) { $role_name = $this->request->get('role_name'); $model = $model->whereHas('roles', function ($query) use ($role_name) { return $query->where('name', $role_name); }); } if ($this->request->filled('role_id')) { $role_id = $this->request->get('role_id'); $model = $model->whereHas('roles', function ($query) use ($role_id) { return $query->where('id', $role_id); }); } if ($this->request->filled('name')) { $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%'); } if ($this->request->filled('user_no')) { $model = $model->where('user_no', 'like', '%' . $this->request->get('user_no')); } if ($this->request->filled('mobile')) { $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile')); } // $admin = login_admin(); // if ($admin) { // if ($admin->hasRole(RoleEnum::SUPER_ADMIN)) { // // } elseif ($admin->hasRole(RoleEnum::SHOP_ADMIN)) { // $model = $model->where('shop_id', $admin['shop_id']); // } else { // $model = $model->where('id', $admin['id']); // } // } // switch ($admin['type']) { // case AdminTypeEnum::ADMIN: // $company_id = $admin['company_id']; // if ($company_id) $model = $model->where('company_id', '=', $company_id); // break; // } // $model = $model->where('type', '=', AdminTypeEnum::ADMIN); return $model; } }