where('uid', $conditions['uid']); } if (isset($conditions['send_time'])){ $query->where('send_time', '<=' , $conditions['send_time']); } })->orderByRaw($sort)->paginate($limit, $fields); return $this->response($result); } public function findBy(array $conditions, array $fields){ $result = DiaryLetter::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 = DiaryLetter::create($data); return $result ? $this->response($result) : $this->error()->fail(); } public function updateBy(array $conditions, array $data) { $result = DiaryLetter::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } if (isset($conditions['send_time'])){ $query->where('send_time', '<=' , $conditions['send_time']); } })->update($data); return $result ? $this->response($result) : $this->error()->fail(); } public function deleteBy(array $conditions) { $result = DiaryLetter::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(); } }