Rule.php 1.8 KB

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