|
|
@@ -32,6 +32,65 @@ class CategoryRepositoryEloquent extends BaseRepository implements CategoryRepos
|
|
|
return $this->model->getNestedList('name', null, ' ');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $input
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function store($input)
|
|
|
+ {
|
|
|
+ if ($input['cate_id'] == 0) {
|
|
|
+ return $this->model->create(['name' => $input['name']]) ? true : false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $category = $this->model->find($input['cate_id']);
|
|
|
+ if (!$category) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $category->children()->create(['name' => $input['name']]) ? true : false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分类修改
|
|
|
+ *
|
|
|
+ * @param array $attributes
|
|
|
+ * @param $id
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function update(array $attributes, $id)
|
|
|
+ {
|
|
|
+ $input['name'] = $attributes['name'];
|
|
|
+ $parentId = $attributes['cate_id'];
|
|
|
+
|
|
|
+ $category = $this->model->find($id);
|
|
|
+ if (!$category) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!parent::update($input, $id)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($parentId != 0 && $category->parent_id != $parentId) {
|
|
|
+
|
|
|
+ $parentCategory = $this->model->find($parentId);
|
|
|
+ if (!$parentCategory) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$category->makeChildOf($parentCategory)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } elseif ($category->parent_id != $parentId && $parentId == 0) {
|
|
|
+ //顶级分类
|
|
|
+ if (!$category->makeRoot()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Boot up the repository, pushing criteria
|
|
|
*/
|