Loading src/Command/MakeModelCommand.php +2 −14 Original line number Diff line number Diff line Loading @@ -308,7 +308,6 @@ class MakeModelCommand extends HyperfCommand $filterFields = ["id", "created_at", "updated_at", "deleted_at"]; $fillAble = ''; $properties = ''; $casts = ''; $timestamps = 0; $softDelete = false; $list = $info['fields']; Loading Loading @@ -348,26 +347,15 @@ class MakeModelCommand extends HyperfCommand ]; $properties .= " * @property " . (isset($pc[$v['data_type']]) ? $pc[$v['data_type']] : "string") . " $" . $name . ($v['column_comment'] ? " " . $v['column_comment'] : "") . "\n"; if ($name == 'created_at' || $name == 'updated_at') { $casts .= "\t\t'" . $name . "'=>'datetime',\n"; $timestamps++; } if ($name == 'deleted_at') { $casts .= "\t\t'" . $name . "'=>'datetime',\n"; $softDelete = true; } if (in_array($name, $filterFields)) { continue; } $fillAble .= "\t\t'" . $name . "'," . "\n"; 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 if ($this->cc[$v['data_type']] == 'decimal') { $casts .= "\t\t'" . $name . "'=>'float',\n"; } else { $casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n"; } } } $relation = ''; if (isset($info['relations']) && $info['relations']) { Loading Loading @@ -414,8 +402,8 @@ class MakeModelCommand extends HyperfCommand $sd = "use SoftDeletes;\n"; $sdn = "use Hyperf\Database\Model\SoftDeletes;\n"; } $patterns = ['%namespace%', "%ClassName%", "%fillAble%", "%casts%", '%relations%', '%timestamps%', '%properties%', '%SoftDelete%']; $replacements = [$sdn, $modelName, $fillAble, $casts, $relation, ($timestamps == 2 ? 'true' : 'false'), $properties, $sd]; $patterns = ['%namespace%', "%ClassName%", "%fillAble%", '%relations%', '%timestamps%', '%properties%', '%SoftDelete%']; $replacements = [$sdn, $modelName, $fillAble, $relation, ($timestamps == 2 ? 'true' : 'false'), $properties, $sd]; $content = $this->buildField($patterns, $replacements, $content); $this->writeToFile($file, $content); Loading src/Command/stubs/model.stub +7 −14 Original line number Diff line number Diff line Loading @@ -19,27 +19,20 @@ namespace App\Model; class %ClassName% extends Model { %SoftDelete% /** * 可写入数据的字段. * @var array * 是否使用时间戳管理 * @var bool */ protected $fillable = [ %fillAble% ]; public $timestamps = %timestamps%; /** * 字段转换数据类型的字段 * 可写入数据的字段. * @var array */ protected $casts = [ %casts% protected $fillable = [ %fillAble% ]; /** * 是否使用时间戳管理 * @var bool */ public $timestamps = %timestamps%; %relations% } Loading
src/Command/MakeModelCommand.php +2 −14 Original line number Diff line number Diff line Loading @@ -308,7 +308,6 @@ class MakeModelCommand extends HyperfCommand $filterFields = ["id", "created_at", "updated_at", "deleted_at"]; $fillAble = ''; $properties = ''; $casts = ''; $timestamps = 0; $softDelete = false; $list = $info['fields']; Loading Loading @@ -348,26 +347,15 @@ class MakeModelCommand extends HyperfCommand ]; $properties .= " * @property " . (isset($pc[$v['data_type']]) ? $pc[$v['data_type']] : "string") . " $" . $name . ($v['column_comment'] ? " " . $v['column_comment'] : "") . "\n"; if ($name == 'created_at' || $name == 'updated_at') { $casts .= "\t\t'" . $name . "'=>'datetime',\n"; $timestamps++; } if ($name == 'deleted_at') { $casts .= "\t\t'" . $name . "'=>'datetime',\n"; $softDelete = true; } if (in_array($name, $filterFields)) { continue; } $fillAble .= "\t\t'" . $name . "'," . "\n"; 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 if ($this->cc[$v['data_type']] == 'decimal') { $casts .= "\t\t'" . $name . "'=>'float',\n"; } else { $casts .= "\t\t'" . $name . "'=>'" . $this->cc[$v['data_type']] . "',\n"; } } } $relation = ''; if (isset($info['relations']) && $info['relations']) { Loading Loading @@ -414,8 +402,8 @@ class MakeModelCommand extends HyperfCommand $sd = "use SoftDeletes;\n"; $sdn = "use Hyperf\Database\Model\SoftDeletes;\n"; } $patterns = ['%namespace%', "%ClassName%", "%fillAble%", "%casts%", '%relations%', '%timestamps%', '%properties%', '%SoftDelete%']; $replacements = [$sdn, $modelName, $fillAble, $casts, $relation, ($timestamps == 2 ? 'true' : 'false'), $properties, $sd]; $patterns = ['%namespace%', "%ClassName%", "%fillAble%", '%relations%', '%timestamps%', '%properties%', '%SoftDelete%']; $replacements = [$sdn, $modelName, $fillAble, $relation, ($timestamps == 2 ? 'true' : 'false'), $properties, $sd]; $content = $this->buildField($patterns, $replacements, $content); $this->writeToFile($file, $content); Loading
src/Command/stubs/model.stub +7 −14 Original line number Diff line number Diff line Loading @@ -19,27 +19,20 @@ namespace App\Model; class %ClassName% extends Model { %SoftDelete% /** * 可写入数据的字段. * @var array * 是否使用时间戳管理 * @var bool */ protected $fillable = [ %fillAble% ]; public $timestamps = %timestamps%; /** * 字段转换数据类型的字段 * 可写入数据的字段. * @var array */ protected $casts = [ %casts% protected $fillable = [ %fillAble% ]; /** * 是否使用时间戳管理 * @var bool */ public $timestamps = %timestamps%; %relations% }