where('id', $conditions['id']); } if (isset($conditions['name'])){ $query->where('name', 'like' , '%'.$conditions['name'].'%'); } if (isset($conditions["isSubject"])){ $query->where('is_subject', "=",0); } if (isset($conditions["is_enable"])){ $query->where('is_enable', $conditions["is_enable"]); } })->orderByRaw($sort)->paginate($limit, $fields); return $this->response($result); } public function findBy(array $conditions, array $fields){ $result = MentalityDrillCategory::with(['mentalityDrill'=>function($with){ $with->select(['id','pic','name']); }])->where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->first($fields); return $result ? $this->response($result) : $this->error()->dataDoesNotExist(); } public function create(array $data) { $result = MentalityDrillCategory::create($data); return $result ? $this->response($result) : $this->error()->fail(); } public function updateBy(array $conditions, array $data) { $result = MentalityDrillCategory::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->update($data); return $result ? $this->response($result) : $this->error()->fail(); } public function deleteBy(array $conditions) { $result = MentalityDrillCategory::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } })->delete(); return $result ? $this->response($result) : $this->error()->fail(); } }