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