diff --git a/.gitignore b/.gitignore index 3b37fa2..2f12e79 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ npm-debug.log yarn-error.log /.idea /.vscode -.run \ No newline at end of file +.run +composer.lock \ No newline at end of file diff --git a/src/Commands/EloquentDocsGeneratorCommand.php b/src/Commands/EloquentDocsGeneratorCommand.php index 4b11ec1..0c28536 100644 --- a/src/Commands/EloquentDocsGeneratorCommand.php +++ b/src/Commands/EloquentDocsGeneratorCommand.php @@ -26,8 +26,22 @@ public function handle( GeneratePhpDocService $generatePhpDocService, Filesystem $filesystem ): int { - $modelClass = $this->argument('model'); - if (!class_exists($modelClass)) { + $modelInput = $this->argument('model'); + + $possibleModelClasses = [ + $modelInput, + str_replace('\\', '\\\\', $modelInput), + 'App\\Models\\' . $modelInput, + ]; + + foreach ($possibleModelClasses as $possibleModelClass) { + if (class_exists($possibleModelClass)) { + $modelClass = $possibleModelClass; + break; + } + } + + if (!isset($modelClass)) { return $this->error("Class $modelClass doesn't exists.") || 1; } @@ -97,5 +111,5 @@ protected function writePhpDoc(Filesystem $filesystem, string $modelClass, strin $filesystem->put($filePath, $fileContent); $this->info('Wrote phpDoc scope to ' . $filePath); - } -} \ No newline at end of file + } +}