dbms/app/Models/Equipment/Part/CpuModel.php
2025-07-11 13:23:26 +09:00

51 lines
1.4 KiB
PHP

<?php
namespace App\Models\Equipment\Part;
use App\Entities\Equipment\Part\CpuEntity;
class CpuModel extends PartModel
{
const TABLE = "cpuinfo";
const PK = "uid";
const TITLE = "model";
protected $table = self::TABLE;
protected $primaryKey = self::PK;
protected $returnType = CpuEntity::class;
protected $allowedFields = [
"model",
"status",
"updated_at"
];
public function __construct()
{
parent::__construct();
}
final public function getFormFieldRule(string $action, string $field): string
{
if (is_array($field)) {
throw new \Exception(__FUNCTION__ . "=> field가 array 입니다.\n" . var_export($field, true));
}
switch ($field) {
case "model":
$rule = "required|trim|string";
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->table}.{$field}]" : "";
break;
case "price":
$rule = "required|numeric";
break;
default:
$rule = parent::getFormFieldRule($action, $field);
break;
}
return $rule;
}
//List 검색용
//OrderBy 처리
public function setOrderBy(string $field, $value): void
{
$this->orderBy('model', 'ASC', false);
parent::setOrderBy($field, $value);
}
}