Rule.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 审计规则.
  6. *
  7. * @property int $id
  8. * @property int $type 类型:1-正则表达式、2-域名、3-IP、4-协议
  9. * @property string $name 规则描述
  10. * @property string $pattern 规则值
  11. * @property-read string $type_api_label
  12. * @property-read string $type_label
  13. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\RuleGroup[] $rule_groups
  14. * @property-read int|null $rule_groups_count
  15. * @method static \Illuminate\Database\Eloquent\Builder|Rule newModelQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|Rule newQuery()
  17. * @method static \Illuminate\Database\Eloquent\Builder|Rule query()
  18. * @method static \Illuminate\Database\Eloquent\Builder|Rule whereId($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|Rule whereName($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|Rule wherePattern($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|Rule whereType($value)
  22. * @mixin \Eloquent
  23. */
  24. class Rule extends Model
  25. {
  26. public $timestamps = false;
  27. protected $table = 'rule';
  28. protected $guarded = [];
  29. public function getTypeLabelAttribute(): string
  30. {
  31. switch ($this->attributes['type']) {
  32. case 1:
  33. $type_label = '正则表达式';
  34. break;
  35. case 2:
  36. $type_label = '域 名';
  37. break;
  38. case 3:
  39. $type_label = 'I P';
  40. break;
  41. case 4:
  42. $type_label = '协 议';
  43. break;
  44. default:
  45. $type_label = '未 知';
  46. }
  47. return $type_label;
  48. }
  49. public function getTypeApiLabelAttribute(): string
  50. {
  51. switch ($this->attributes['type']) {
  52. case 1:
  53. $type_api_label = 'reg';
  54. break;
  55. case 2:
  56. $type_api_label = 'domain';
  57. break;
  58. case 3:
  59. $type_api_label = 'ip';
  60. break;
  61. case 4:
  62. $type_api_label = 'protocol';
  63. break;
  64. default:
  65. $type_api_label = 'unknown';
  66. }
  67. return $type_api_label;
  68. }
  69. public function rule_groups()
  70. {
  71. return $this->belongsToMany(RuleGroup::class);
  72. }
  73. }