Files
ProxyPanel/app/Models/Rule.php
兔姬桑 f25f2aea62 优化数据库 与 简化控制器 & more
1. 继续修改表表关系,与关联字段的限制;
2. 通过表表关系,简化一部分代码,自动让Laravel建立关联;
3. 拆分验证 与 优化数据创建与修改的获取数据操作;
4. 修改部分无意义的数据名称;
2020-12-28 12:09:20 +08:00

65 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* 审计规则.
*/
class Rule extends Model
{
public $timestamps = false;
protected $table = 'rule';
protected $guarded = ['id'];
public function getTypeLabelAttribute(): string
{
switch ($this->attributes['type']) {
case 1:
$type_label = '正则表达式';
break;
case 2:
$type_label = '域 名';
break;
case 3:
$type_label = 'I P';
break;
case 4:
$type_label = '协 议';
break;
default:
$type_label = '未 知';
}
return $type_label;
}
public function getTypeApiLabelAttribute(): string
{
switch ($this->attributes['type']) {
case 1:
$type_api_label = 'reg';
break;
case 2:
$type_api_label = 'domain';
break;
case 3:
$type_api_label = 'ip';
break;
case 4:
$type_api_label = 'protocol';
break;
default:
$type_api_label = 'unknown';
}
return $type_api_label;
}
public function rule_groups()
{
return $this->belongsToMany(RuleGroup::class);
}
}