58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Equipment;
|
|
|
|
use App\Entities\Equipment\CSEntity;
|
|
|
|
class CSModel extends EquipmentModel
|
|
{
|
|
const TABLE = "csinfo";
|
|
const PK = "uid";
|
|
const TITLE = "ip";
|
|
protected $table = self::TABLE;
|
|
protected $primaryKey = self::PK;
|
|
protected $returnType = CSEntity::class;
|
|
protected $allowedFields = [
|
|
"clientinfo_uid",
|
|
"serviceinfo_uid",
|
|
"serverinfo_uid",
|
|
"type",
|
|
"ip",
|
|
"accountid",
|
|
"domain",
|
|
"price",
|
|
"status",
|
|
"updated_at"
|
|
];
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
public function getFormRule(string $action, string $field): string
|
|
{
|
|
if (is_array($field)) {
|
|
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
|
|
}
|
|
switch ($field) {
|
|
case "type":
|
|
$rule = "required|trim|string";
|
|
break;
|
|
case "ip":
|
|
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[" . $this->getTable() . "." . $field . "]" : "";
|
|
break;
|
|
case "price":
|
|
$rule = "required|numeric";
|
|
break;
|
|
case "accountid":
|
|
case "domain":
|
|
$rule = "permit_empty|trim|string";
|
|
break;
|
|
default:
|
|
$rule = parent::getFormRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
}
|