hasOne(Contract::class, 'id', 'contract_id'); } /** * 搜索器:合同ID */ public function searchContractIdAttr($query, $value, $data) { if ($value) { $query->where("contract_id", $value); } } /** * 搜索器:占位符 */ public function searchPlaceholderAttr($query, $value, $data) { if ($value) { $query->where("placeholder", 'like', '%' . $value . '%'); } } /** * 字段类型获取器 * @param $value * @return string */ public function getFieldTypeTextAttr($value) { $typeMap = [ 'text' => '文本', 'number' => '数字', 'date' => '日期', 'datetime' => '日期时间' ]; return $typeMap[$this->getAttr('field_type')] ?? '文本'; } /** * 状态获取器 * @param $value * @return string */ public function getIsActiveTextAttr($value) { return $this->getAttr('is_active') ? '启用' : '禁用'; } }