trafficmonitor/app/Forms/TrafficForm.php
2025-11-13 16:10:34 +09:00

40 lines
1.0 KiB
PHP

<?php
namespace App\Forms;
use App\Forms\CommonForm;
class TrafficForm extends CommonForm
{
public function __construct()
{
parent::__construct();
$this->setActionButtons(['view' => ICONS['SEARCH'], 'dashboard' => ICONS['CHART'], 'delete' => ICONS['DELETE']]);
}
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "client":
case "interface":
case "status":
$rule = "required|trim|string";
break;
case "server":
case "switch":
$rule = "required|trim|string";
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
break;
case "server_ip":
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
break;
case "ip":
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
break;
default:
$rule = parent::getFormRule($action, $field);
break;
}
return $rule;
}
}