Rule.php 982 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 getTypeLabelAttribute(): string
  14. {
  15. return [
  16. 1 => trans('admin.rule.type.reg'),
  17. 2 => trans('admin.rule.type.domain'),
  18. 3 => trans('admin.rule.type.ip'),
  19. 4 => trans('admin.rule.type.protocol'),
  20. ][$this->attributes['type']] ?? trans('common.status.unknown');
  21. }
  22. public function getTypeApiLabelAttribute(): string
  23. {
  24. return [
  25. 1 => 'reg',
  26. 2 => 'domain',
  27. 3 => 'ip',
  28. 4 => 'protocol',
  29. ][$this->attributes['type']] ?? 'unknown';
  30. }
  31. public function rule_groups(): BelongsToMany
  32. {
  33. return $this->belongsToMany(RuleGroup::class);
  34. }
  35. }