43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Part;
|
|
|
|
use App\Models\CommonModel;
|
|
|
|
abstract class PartModel extends CommonModel
|
|
{
|
|
protected 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 "title":
|
|
$rule = "required|trim|string";
|
|
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[" . $this->getTable() . "." . $field . "]" : "";
|
|
break;
|
|
case "clientinfo_uid":
|
|
case "serviceinfo_uid":
|
|
case "serverinfo_uid":
|
|
$rule = "permit_empty|trim|string";
|
|
break;
|
|
case "price":
|
|
case "stock":
|
|
$rule = "required|numeric";
|
|
break;
|
|
case "status":
|
|
$rule = "permit_empty|trim|string";
|
|
break;
|
|
default:
|
|
$rule = parent::getFormRule($action, $field);
|
|
break;
|
|
}
|
|
return $rule;
|
|
}
|
|
}
|