where('uid', $conditions['uid']); } })->orderByRaw($sort)->paginate($limit, $fields); return $this->response($result); } public function findBy(array $conditions, array $fields){ $result = DiarySleepLevel::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->first($fields); return $result ? $this->response($result) : $this->error()->dataDoesNotExist(); } public function create(array $data) { $result = DiarySleepLevel::create($data); return $result ? $this->response($result) : $this->error()->fail(); } public function updateBy(array $conditions, array $data) { $result = DiarySleepLevel::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->update($data); return $result ? $this->response($result) : $this->error()->fail(); } public function deleteBy(array $conditions) { $result = DiarySleepLevel::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->delete(); return $result ? $this->response($result) : $this->error()->fail(); } }