Commit 38da851f authored by 王源's avatar 王源 🎧

修改生成模型类方法

parent 0be2078e
...@@ -356,7 +356,11 @@ class MakeModelCommand extends HyperfCommand ...@@ -356,7 +356,11 @@ class MakeModelCommand extends HyperfCommand
} }
$fillAble .= "\t\t'" . $name . "'," . "\n"; $fillAble .= "\t\t'" . $name . "'," . "\n";
if (isset($this->cc[$v['data_type']]) && $this->cc[$v['data_type']] != 'string') { if (isset($this->cc[$v['data_type']]) && $this->cc[$v['data_type']] != 'string') {
$casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n"; if ($this->cc[$v['data_type']] == 'timestamp') {
$casts .= "\t\t'" . $name . "'=>'datetime',\n";
} else {
$casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n";
}
} }
} }
$relation = ''; $relation = '';
...@@ -364,10 +368,8 @@ class MakeModelCommand extends HyperfCommand ...@@ -364,10 +368,8 @@ class MakeModelCommand extends HyperfCommand
$relation .= "\n"; $relation .= "\n";
if (isset($info['relations']['belongsTo'])) { if (isset($info['relations']['belongsTo'])) {
foreach ($info['relations']['belongsTo'] as $v) { foreach ($info['relations']['belongsTo'] as $v) {
$relation .= "\n\t/**\n\t* 属于" . $v['relation_model_name'] . "的关联"; $relation .= "\n\t/**\n\t* 属于" . $v['relation_model_name'] . "的关联\n\t*/";
$relation .= "\n\t* @return " . $v['relation_model_name']; $relation .= "\n\tpublic function " . $v['function'] . "()";
$relation .= "\n\t**/";
$relation .= "\n\tpublic function " . $v['function'] . "() : " . $v['relation_model_name'];
$relation .= "\n\t{"; $relation .= "\n\t{";
$relation .= "\n\t\t" . 'return $this->belongsTo(' . $v['relation_model_name'] . "::class,'" . $v['local_table_key'] . "','{$v['relation_table_key']}' );"; $relation .= "\n\t\t" . 'return $this->belongsTo(' . $v['relation_model_name'] . "::class,'" . $v['local_table_key'] . "','{$v['relation_table_key']}' );";
$relation .= "\n\t}"; $relation .= "\n\t}";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment