48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use Dcat\Admin\Traits\ModelTree;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kalnoy\Nestedset\NodeTrait;
|
|
|
|
class ArticleCategory extends Model
|
|
{
|
|
use NodeTrait;
|
|
use ModelTree;
|
|
use HasDateTimeFormatter;
|
|
|
|
protected $table = 'article_categories';
|
|
|
|
protected $casts = [
|
|
'is_show' => 'boolean',
|
|
'is_recommend' => 'boolean',
|
|
];
|
|
|
|
// 排序字段名称,默认值为 order
|
|
protected $orderColumn = 'sort';
|
|
|
|
// 标题字段名称,默认值为 title
|
|
protected $titleColumn = 'name';
|
|
|
|
public function getDefaultParentId()
|
|
{
|
|
return $this->parent_id;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
parent::updated(function ($articleCategory) {
|
|
if ($articleCategory->wasChanged('is_show')) {//如果改变显示隐藏
|
|
//影响下级分类;
|
|
$articleCategory->descendants()->update(['is_show' => $articleCategory->is_show]);
|
|
//影响上级分类;能力有限无法实现
|
|
}
|
|
});
|
|
}
|
|
}
|