'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]); //影响上级分类;能力有限无法实现 } }); } public function scopeShow($q) { return $q->where('is_show', 1); } public function scopeSort($q) { return $q->orderBy('is_recommend', 'desc')->orderBy('sort', 'desc')->orderBy('created_at', 'desc'); } }