update cms
This commit is contained in:
@@ -13,8 +13,12 @@
|
||||
|
||||
namespace catchAdmin\cms\model;
|
||||
|
||||
use catchAdmin\cms\model\events\TagsEvent;
|
||||
|
||||
class Tags extends BaseModel
|
||||
{
|
||||
use TagsEvent;
|
||||
|
||||
// 表名
|
||||
public $name = 'cms_tags';
|
||||
// 数据库字段映射
|
||||
@@ -38,7 +42,47 @@ class Tags extends BaseModel
|
||||
'deleted_at',
|
||||
);
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @auth CatchAdmin
|
||||
* @time 2021年05月22日
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
// 分页列表
|
||||
return $this->catchSearch()
|
||||
->field($this->aliasField('*'))
|
||||
->withCount('articles')
|
||||
->catchOrder()
|
||||
->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签下的文章
|
||||
*
|
||||
* @author CatchAdmin
|
||||
* @time 2021年05月24日
|
||||
* @return \think\model\relation\BelongsToMany
|
||||
*/
|
||||
public function articles(): \think\model\relation\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Articles::class, 'cms_article_relate_tags',
|
||||
'article_id', 'tag_id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签 name 搜索
|
||||
*
|
||||
* @author CatchAdmin
|
||||
* @time 2021年05月24日
|
||||
* @param $query
|
||||
* @param $value
|
||||
* @return void
|
||||
*/
|
||||
public function searchNameAttr($query, $value)
|
||||
{
|
||||
$query->whereLike('name', $value);
|
||||
|
12
catch/cms/model/events/TagsEvent.php
Normal file
12
catch/cms/model/events/TagsEvent.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace catchAdmin\cms\model\events;
|
||||
|
||||
use catchAdmin\cms\model\Tags;
|
||||
|
||||
trait TagsEvent
|
||||
{
|
||||
public static function onAfterDelete(Tags $tag)
|
||||
{
|
||||
$tag->articles()->detach($tag->articles()->select()->column('id'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user