SsConfig.php 684 B

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