办事指南支持分类

This commit is contained in:
2025-06-18 14:10:03 +08:00
parent 0d82756571
commit e7d86d685f
2 changed files with 10 additions and 0 deletions

View File

@ -8,7 +8,13 @@ use think\admin\Controller;
class Tutorial extends Controller
{
public function index() {
$categoryId = $this->request->get('cid');
$query = CmsTutorial::mk()->where('status', 1);
if ($categoryId > 0) {
$query->hasWhere('cateids', function ($subQuery) use ($categoryId) {
$subQuery->where('cid', $categoryId);
});
}
$articles = $query->order('sort asc,create_at desc')->paginate();
$this->success('获取文章列表', $articles);
}

View File

@ -14,6 +14,10 @@ class CmsTutorial extends Model
return $this->belongsToMany(CmsCategory::class, CmsTutorialCategory::class, 'cid', 'tid');
}
public function cateids()
{
return $this->hasMany(CmsTutorialCategory::class, 'tid');
}
/**
* 获取分类ID列表
*/