-
-
Couldn't load subscription status.
- Fork 1.2k
Allowing table inspection to gracefully fail so other IDE helpers for models may still be generated #1528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Allowing table inspection to gracefully fail so other IDE helpers for models may still be generated #1528
Changes from 1 commit
81aa9f9
9a27bee
7f0e6b5
5f5feba
feef29a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,6 +252,8 @@ protected function generateDocs($loadModels, $ignore = '') | |
| $this->laravel['config']->get('ide-helper.ignored_models', []) | ||
| ); | ||
|
|
||
| $skippedGeneratingTablePropertiesForModels = []; | ||
|
|
||
| foreach ($models as $name) { | ||
| if (in_array($name, $ignore)) { | ||
| if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | ||
|
|
@@ -280,7 +282,20 @@ protected function generateDocs($loadModels, $ignore = '') | |
|
|
||
| $model = $this->laravel->make($name); | ||
|
|
||
| $this->getPropertiesFromTable($model); | ||
| try { | ||
| $this->getPropertiesFromTable($model); | ||
| } catch (Throwable $e) { | ||
| $modelName = $model::class; | ||
|
|
||
| if ($this->warningsAreAllowedForForModel($model)) { | ||
| $connectionName = $model->getConnectionName() ?? $this->laravel['config']->get('database.default'); | ||
| $driver = $model->getConnection()::class; | ||
|
|
||
| $this->warn("Could not get table properties for model [{$modelName}] using connection [{$connectionName}]. The underlying database driver [{$driver}] may not be supported."); | ||
|
||
|
|
||
| $skippedGeneratingTablePropertiesForModels[] = $model; | ||
| } | ||
| } | ||
|
|
||
| if (method_exists($model, 'getCasts')) { | ||
| $this->castPropertiesType($model); | ||
|
|
@@ -304,6 +319,16 @@ protected function generateDocs($loadModels, $ignore = '') | |
| } | ||
| } | ||
|
|
||
| if (! empty($skippedGeneratingTablePropertiesForModels)) { | ||
| $classes = collect($skippedGeneratingTablePropertiesForModels) | ||
| ->map(fn ($model) => ' • ' . $model::class); | ||
| $this->warn('Could not inspect table properties for some models. See output above for any warnings'); | ||
| $this->warn('Models without table inspection:'); | ||
| $this->newLine(); | ||
| $this->warn($classes->implode(PHP_EOL)); | ||
| $this->newLine(); | ||
| } | ||
|
|
||
| return $output; | ||
| } | ||
|
|
||
|
|
@@ -1626,4 +1651,10 @@ protected function setForeignKeys($schema, $table) | |
| } | ||
| } | ||
| } | ||
|
|
||
| protected function warningsAreAllowedForForModel(Model $model): bool | ||
| { | ||
| return collect($this->laravel['config']->get('ide-helper.silenced_models')) | ||
| ->doesntContain($model::class); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice