小调整

This commit is contained in:
2020-09-25 13:56:57 +08:00
parent e56cdf597a
commit 737a66b0c6
5 changed files with 59 additions and 48 deletions

View File

@@ -20,7 +20,7 @@ class CategoryController extends Controller
} else {
$articles = $category->relations(Category::TYPE_ARTICLE)->paginate(8);
$parent = $category;
if ($category->childrens->isEmpty() && $category->patent) {
if ($category->childrens->isEmpty() && $category->parent) {
$parent = $category->parent;
}

View File

@@ -74,4 +74,15 @@ class Category extends Model
return $ids;
}
public function getTop()
{
$parent = $this;
while ($parent->parent_id) {
$parent->parent;
}
return $parent;
}
}