You've already forked guangan
40 lines
864 B
PHP
40 lines
864 B
PHP
<?php
|
|
|
|
namespace plugin\cms\model;
|
|
|
|
use think\admin\Model;
|
|
|
|
class CmsTutorial extends Model
|
|
{
|
|
/**
|
|
* 定义与分类的多对多关系
|
|
*/
|
|
public function categories()
|
|
{
|
|
return $this->belongsToMany(CmsCategory::class, CmsTutorialCategory::class, 'cid', 'tid');
|
|
}
|
|
|
|
public function cateids()
|
|
{
|
|
return $this->hasMany(CmsTutorialCategory::class, '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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |