catchAdmin/catch/cms/model/scopes/CategoryScope.php
2021-05-22 11:02:45 +08:00

37 lines
1.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | Catch-CMS Design On 2020
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catchAdmin\cms\model\scopes;
use catchAdmin\cms\model\Articles;
use think\facade\Db;
trait CategoryScope
{
/**
* 文章数量
*
* @time 2020年06月17日
* @param $query
* @return mixed
*/
public function scopeArticlesCount($query)
{
return $query->addSelectSub(function () {
$article = app(Articles::class);
return $article->field(Db::raw('count(*)'))
->whereColumn($this->aliasField('id'), $article->aliasField('category_id'));
}, 'articles');
}
}