update cms
This commit is contained in:
parent
034705bb3d
commit
3bad548d10
@ -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'));
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ class SiteLink extends CatchTable
|
||||
Actions::create()
|
||||
])
|
||||
->withSearch([
|
||||
Search::label('网站标题')->input('title', '请输入网站标题')
|
||||
Search::label('网站标题')->input('title', '请输入标题')
|
||||
])
|
||||
->withBind()
|
||||
->withDialogWidth('40%')
|
||||
|
@ -14,10 +14,12 @@ class Tags extends CatchTable
|
||||
// TODO: Implement table() method.
|
||||
return $this->getTable('tags')
|
||||
->header([
|
||||
HeaderItem::label('编号')->prop('id'),
|
||||
HeaderItem::label('编号')->prop('id')->width(100),
|
||||
|
||||
HeaderItem::label('名称')->prop('name'),
|
||||
|
||||
HeaderItem::label('文章数量')->prop('articles_count'),
|
||||
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
|
||||
HeaderItem::label('操作')->actions([
|
||||
|
Loading…
x
Reference in New Issue
Block a user