You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/TypeScriptifyModel.php
+81-62Lines changed: 81 additions & 62 deletions
Original file line number
Diff line number
Diff line change
@@ -51,10 +51,24 @@ final class TypeScriptifyModel {
51
51
52
52
/**
53
53
* @param string $fullyQualifiedModelName The fully qualified model class name.
54
+
* @param ?array<string,string> $convertedModelsMap The map of `fully qualified model name => interface name` definitions this class can refer to instead of generating its own definitions.
54
55
*/
55
56
publicfunction__construct(
56
-
privatereadonlystring$fullyQualifiedModelName,
57
+
privatestring$fullyQualifiedModelName,
58
+
private ?array &$convertedModelsMap = []
57
59
) {
60
+
// For consistency in comparisons that happen throughout the lifecycle of this class,
61
+
// we need all fully qualified model names to have a leading \.
thrownewException('Your database connection is currently unsupported! The following database connections are supported: ' . implode(', ', self::SUPPORTED_DATABASE_CONNECTIONS));
70
+
}
71
+
58
72
$this->model = new$fullyQualifiedModelName;
59
73
60
74
$this->modelForeignKeyConstraints = collect(
@@ -271,10 +285,17 @@ private function getTypeScriptType(stdClass $columnSchema): string {
271
285
if ($this->isAttributeRelation($columnSchema->Field)) {
* Set whether we should include the model's protected $hidden attributes.
358
329
*
@@ -374,14 +345,62 @@ public function includeHidden(bool $includeHidden): self {
374
345
* @throws \Exception
375
346
*/
376
347
publicfunctiongenerate(): string {
377
-
if (!$this->hasValidModel()) {
378
-
thrownewException('That\'s not a valid model!');
379
-
}
348
+
$tableColumns = collect(DB::select(DB::raw('SHOW COLUMNS FROM ' . $this->model->getTable())));
380
349
381
-
if (!$this->hasSupportedDatabaseConnection()) {
382
-
thrownewException('Your database connection is currently unsupported! The following database connections are supported: ' . implode(', ', self::SUPPORTED_DATABASE_CONNECTIONS));
0 commit comments