Add magic *_exists properties (#1712)

* Added magic `*_exists` properties.

* fix return datatype

* disabled by default

---------

Co-authored-by: Joel Stein <[email protected]>
This commit is contained in:
erikn69
2025-07-17 22:11:57 +02:00
committed by GitHub
co-authored by Joel Stein
parent 877f5ed0a7
commit 8d00250cba
15 changed files with 51 additions and 5 deletions
+12
View File
@@ -114,6 +114,7 @@ class ModelsCommand extends Command
protected $write_model_magic_where;
protected $write_model_relation_count_properties;
protected $write_model_relation_exists_properties;
protected $properties = [];
protected $methods = [];
protected $write = false;
@@ -173,6 +174,8 @@ class ModelsCommand extends Command
$this->write_model_external_builder_methods = $this->laravel['config']->get('ide-helper.write_model_external_builder_methods', true);
$this->write_model_relation_count_properties =
$this->laravel['config']->get('ide-helper.write_model_relation_count_properties', true);
$this->write_model_relation_exists_properties =
$this->laravel['config']->get('ide-helper.write_model_relation_exists_properties', false);
$this->write = $this->write_mixin ? true : $this->write;
//If filename is default and Write is not specified, ask what to do
@@ -820,6 +823,15 @@ class ModelsCommand extends Command
// What kind of comments should be added to the relation count here?
);
}
if ($this->write_model_relation_exists_properties) {
$this->setProperty(
Str::snake($method) . '_exists',
'bool|null',
true,
false
// What kind of comments should be added to the relation count here?
);
}
} elseif (
$relationReturnType === 'morphTo' ||
(