SsConfig.php 762 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 配置信息.
  7. */
  8. class SsConfig extends Model
  9. {
  10. public $timestamps = false;
  11. protected $table = 'ss_config';
  12. protected $guarded = [];
  13. public function scopeDefault(Builder $query): Builder
  14. { // 筛选默认
  15. return $query->whereIsDefault(1);
  16. }
  17. public function scopeType(Builder $query, int $type): Builder
  18. { // 筛选类型
  19. return $query->whereType($type);
  20. }
  21. public function setDefault(): bool
  22. { // 设置默认
  23. self::type($this->type)->default()->update(['is_default' => 0]); // unset original default config
  24. return $this->update(['is_default' => 1]);
  25. }
  26. }