调整分类

This commit is contained in:
2021-12-10 15:29:00 +08:00
parent 5921a59945
commit ce4dc96c55
2 changed files with 14 additions and 1 deletions

View File

@@ -36,7 +36,8 @@ class CategoryController extends Controller
->paginate();
$parent = $category;
if ($category->childrens->isEmpty() && $category->parent) {
if (! $category->getChildrenCount() && $category->parent) {
$parent = $category->parent;
}

View File

@@ -93,4 +93,16 @@ class Category extends Model
return $parent;
}
/**
* Notes: 获取下级分类数量
*
* @Author: 玄尘
* @Date: 2021/12/10 15:27
* @return int
*/
public function getChildrenCount(): int
{
return $this->childrens()->where('status', 1)->count();
}
}