You've already forked guangan
办事指南分类
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
plugs/think-plugs-cms/src/model/CmsTutorialCategory.php
Normal file
24
plugs/think-plugs-cms/src/model/CmsTutorialCategory.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\cms\model;
|
||||
|
||||
use think\model\Pivot;
|
||||
|
||||
class CmsTutorialCategory extends Pivot
|
||||
{
|
||||
/**
|
||||
* 关联分类模型
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(CmsCategory::class, 'cid', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联办事指南模型
|
||||
*/
|
||||
public function tutorial()
|
||||
{
|
||||
return $this->belongsTo(CmsTutorial::class, 'tid', 'id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user