办事指南分类

This commit is contained in:
2025-03-14 11:36:03 +08:00
parent 0219e2f764
commit 53e7be1156
6 changed files with 86 additions and 4 deletions

View File

@ -6,5 +6,31 @@ use think\admin\Model;
class CmsTutorial extends Model
{
/**
* 定义与分类的多对多关系
*/
public function categories()
{
return $this->belongsToMany(CmsCategory::class, CmsTutorialCategory::class, 'cid', 'tid');
}
/**
* 获取分类ID列表
*/
public function getCategoryIdsAttr()
{
return $this->categories()->column('id');
}
public function setCategoryIdsAttr($value)
{
if ($this->isExists()) {
$this->categories()->detach();
if (is_array($value)) {
foreach ($value as $cid) {
$this->categories()->attach($cid);
}
}
}
}
}