Skip to content

Commit 9d959b4

Browse files
committed
Fixed lenght
1 parent 8edbf4e commit 9d959b4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Data/Schema.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public function getData()
4545
: data_get($foreignColumn, 'foreign_table');
4646
$columnType = 'FK -> '.$foreignTable;
4747
}
48-
$length = is_object($column) && method_exists($column, 'getLength') ? $column->getLength() : count($columns);
48+
49+
$length = is_object($column) && method_exists($column, 'getLength') ? $column->getLength() : $this->extractNumber(data_get($column, 'type'));
4950

5051
$details['column'] = $columnName;
5152
$details['type'] = $columnType.$this->determineUnsigned($column);
@@ -67,6 +68,13 @@ public function getData()
6768
return $this->collections;
6869
}
6970

71+
private function extractNumber(string $type): ?int
72+
{
73+
preg_match('/\d+/', $type, $matches);
74+
75+
return ! empty($matches) ? (int) $matches[0] : null;
76+
}
77+
7078
private function determineUnsigned($column)
7179
{
7280
if (is_object($column) && method_exists($column, 'getUnsigned')) {

0 commit comments

Comments
 (0)