dbmsv4/app/Forms/Equipment/ServerPartForm.php
2025-11-21 13:10:03 +09:00

64 lines
1.9 KiB
PHP

<?php
namespace App\Forms\Equipment;
class ServerPartForm extends EquipmentForm
{
public function __construct()
{
parent::__construct();
}
public function getFormRule(string $action, string $field): string
{
switch ($field) {
case "serverinfo_uid":
case "part_uid":
case "cnt":
case "amount":
$rule = "required|numeric";
break;
case "clientinfo_uid":
case "serviceinfo_uid":
case "payment_uid":
$rule = "permit_empty|numeric";
break;
case "title":
case "type":
case "billing":
$rule = "required|trim|string";
break;
case "extra":
$rule = "permit_empty|trim|string";
break;
default:
$rule = parent::getFormRule($action, $field);
break;
}
return $rule;
}
public function getFormOption(string $field, array $options = ['options' => [], 'extras' => [], 'atttributes' => []]): array
{
$tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
switch ($field) {
case 'part_uid':
foreach (service('equipment_serverpartservice')->getEntities() as $entity) {
$tempOptions[$entity->getPK()] = $entity->getTitle();
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
}
$options['options'] = $tempOptions;
break;
case 'serverinfo_uid':
foreach (service('equipment_serverservice')->getEntities() as $entity) {
$tempOptions[$entity->getPK()] = $entity->getTitle();
// $options['attributes'][$entity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $entity->getRole())];
}
$options['options'] = $tempOptions;
break;
default:
$options = parent::getFormOption($field, $options);
break;
}
return $options;
}
}