RuleGroup.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 审计规则分组.
  6. *
  7. * @property int $id
  8. * @property int $type 模式:1-阻断、0-放行
  9. * @property string $name 分组名称
  10. * @property \Illuminate\Support\Carbon $created_at 创建时间
  11. * @property \Illuminate\Support\Carbon $updated_at 最后更新时间
  12. * @property-read string $type_label
  13. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Rule[] $rules
  14. * @property-read int|null $rules_count
  15. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup newModelQuery()
  16. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup newQuery()
  17. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup query()
  18. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup whereCreatedAt($value)
  19. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup whereId($value)
  20. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup whereName($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup whereType($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|RuleGroup whereUpdatedAt($value)
  23. * @mixin \Eloquent
  24. */
  25. class RuleGroup extends Model
  26. {
  27. protected $table = 'rule_group';
  28. protected $guarded = [];
  29. public function getTypeLabelAttribute(): string
  30. {
  31. if ($this->attributes['type']) {
  32. $type_label = '<span class="badge badge-danger">阻 断</span>';
  33. } else {
  34. $type_label = '<span class="badge badge-primary">放 行</span>';
  35. }
  36. return $type_label;
  37. }
  38. public function rules()
  39. {
  40. return $this->belongsToMany(Rule::class);
  41. }
  42. }