Commit 38da851f authored by 王源's avatar 王源
Browse files

修改生成模型类方法

parent 0be2078e
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -356,18 +356,20 @@ 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') {
                if ($this->cc[$v['data_type']] == 'timestamp') {
                    $casts .= "\t\t'" . $name . "'=>'datetime',\n";
                } else {
                    $casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n";
                    $casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n";
                }
                }
            }
            }
        }
        $relation = '';
        $relation = '';
        if (isset($info['relations']) && $info['relations']) {
        if (isset($info['relations']) && $info['relations']) {
            $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}";