You've already forked guangan
办事指南支持分类
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
@ -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列表
|
||||
*/
|
||||
|
Reference in New Issue
Block a user