55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Entities\ProductDeviceEntity;
|
|
use App\Entities\ProductEntity;
|
|
|
|
class ProductDeviceModel extends BaseModel
|
|
{
|
|
protected $table = "tw_product_device";
|
|
protected $returnType = ProductDeviceEntity::class;
|
|
public function __construct()
|
|
{
|
|
parent::__construct('ProductDevic');
|
|
$this->allowedFields = [
|
|
...$this->allowedFields, "product_uid", "device_uid", "device_cnt"
|
|
];
|
|
$this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),];
|
|
}
|
|
final public function getTitleField(): string
|
|
{
|
|
return 'product_uid';
|
|
}
|
|
public function getFieldRule(string $field, array $rules, string $action = ""): array
|
|
{
|
|
switch ($field) {
|
|
case "product_uid":
|
|
case "device_uid":
|
|
$rules[$field] = $this->getUUIDFieldRule('required');
|
|
break;
|
|
case 'device_cnt':
|
|
$rules[$field] = "required|numeric";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules, $action);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getEntity(array $conditions = []): ProductDeviceEntity
|
|
{
|
|
return parent::getEntity($conditions);
|
|
}
|
|
public function create(array $formDatas): ProductDeviceEntity
|
|
{
|
|
$entity = $this->create_process(new ProductDeviceEntity(), $formDatas);
|
|
dd($entity);
|
|
return $entity;
|
|
}
|
|
public function modify(ProductDeviceEntity $entity, array $formDatas): ProductDeviceEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
}
|