You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
687 B

  1. <?php
  2. namespace App\Model\v3;
  3. use App\Model\Model;
  4. use Hyperf\Database\Model\Builder;
  5. use Hyperf\Database\Model\SoftDeletes;
  6. class Category extends Model
  7. {
  8. use SoftDeletes;
  9. protected $table = 'lanzu_category';
  10. protected $appends = [
  11. 'goods_types'
  12. ];
  13. protected function boot(): void
  14. {
  15. parent::boot();
  16. static::addGlobalScope('status', function (Builder $builder) {
  17. $builder->where(['status' => 1])->orderBy('sort', 'desc');
  18. });
  19. }
  20. public function getGoodsTypesAttribute()
  21. {
  22. return self::query()->where(['parent_id' => $this->attributes['id']])->orderBy('sort', 'desc')->get()->toArray();
  23. }
  24. }