Skip to content

Commit 23aa5a0

Browse files
authored
Generate id() column on Laravel 7 and up (#99)
1 parent 57a01ad commit 23aa5a0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Generators/MigrationGenerator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ protected function buildDefinition(Model $model)
6262
$dataType = 'uuid';
6363
}
6464

65-
$definition .= self::INDENT . '$table->' . $dataType . "('{$column->name()}'";
65+
if ($this->isLaravel7orNewer() && $dataType === 'bigIncrements') {
66+
$definition .= self::INDENT . '$table->id(';
67+
} else {
68+
$definition .= self::INDENT . '$table->' . $dataType . "('{$column->name()}'";
69+
}
6670

6771
if (!empty($column->attributes()) && !in_array($column->dataType(), ['id', 'uuid'])) {
6872
$definition .= ', ';
@@ -117,4 +121,9 @@ protected function getPath(Model $model, Carbon $timestamp)
117121
{
118122
return 'database/migrations/' . $timestamp->format('Y_m_d_His') . '_create_' . $model->tableName() . '_table.php';
119123
}
124+
125+
protected function isLaravel7orNewer()
126+
{
127+
return version_compare(app()->version(), '7.0.0', '>=');
128+
}
120129
}

0 commit comments

Comments
 (0)