1
0

Rule.php 1010 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  5. /**
  6. * 审计规则.
  7. */
  8. class Rule extends Model
  9. {
  10. public $timestamps = false;
  11. protected $table = 'rule';
  12. protected $guarded = [];
  13. public function rule_groups(): BelongsToMany
  14. {
  15. return $this->belongsToMany(RuleGroup::class);
  16. }
  17. public function getTypeLabelAttribute(): string
  18. {
  19. return match ($this->type) {
  20. 1 => trans('admin.rule.type.reg'),
  21. 2 => trans('admin.rule.type.domain'),
  22. 3 => trans('admin.rule.type.ip'),
  23. 4 => trans('admin.rule.type.protocol'),
  24. default => trans('common.status.unknown'),
  25. };
  26. }
  27. public function getTypeApiLabelAttribute(): string
  28. {
  29. return match ($this->type) {
  30. 1 => 'reg',
  31. 2 => 'domain',
  32. 3 => 'ip',
  33. 4 => 'protocol',
  34. default => 'unknown',
  35. };
  36. }
  37. }