Skip to content

Commit bbee274

Browse files
authored
MakeModelCommand timestamps
1 parent 6654728 commit bbee274

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Commands/MakeModelCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ protected function createModel($class, $namespace, $file, $connection = null)
112112
$pk = 'id';
113113
$properties = '';
114114
$connection = $connection ?: config('database.default');
115+
$timestamps = 'false';
116+
$hasCreatedAt = false;
117+
$hasUpdatedAt = false;
115118
try {
116119
$prefix = config("database.connections.$connection.prefix") ?? '';
117120
$database = config("database.connections.$connection.database");
@@ -136,12 +139,19 @@ protected function createModel($class, $namespace, $file, $connection = null)
136139
$item->COLUMN_COMMENT .= "(主键)";
137140
}
138141
$type = $this->getType($item->DATA_TYPE);
142+
if ($item->COLUMN_NAME === 'created_at') {
143+
$hasCreatedAt = true;
144+
}
145+
if ($item->COLUMN_NAME === 'updated_at') {
146+
$hasUpdatedAt = true;
147+
}
139148
$properties .= " * @property $type \${$item->COLUMN_NAME} {$item->COLUMN_COMMENT}\n";
140149
}
141150
} catch (\Throwable $e) {
142151
echo $e->getMessage() . PHP_EOL;
143152
}
144153
$properties = rtrim($properties) ?: ' *';
154+
$timestamps = $hasCreatedAt && $hasUpdatedAt ? 'true' : 'false';
145155
$model_content = <<<EOF
146156
<?php
147157
@@ -180,7 +190,7 @@ class $class extends Model
180190
*
181191
* @var bool
182192
*/
183-
public \$timestamps = false;
193+
public \$timestamps = $timestamps;
184194
185195
186196
}

0 commit comments

Comments
 (0)