Fix issue where \Eloquent is not included when using write_mixin (#1352)

* Check for exact mixin name when writing

* changelog

* add mixin to test class

Co-authored-by: Barry vd. Heuvel <[email protected]>
This commit is contained in:
Jefemy
2022-08-11 12:39:26 +02:00
committed by GitHub
co-authored by Barry vd. Heuvel
parent 07f5eaea73
commit c8f0f914e3
3 changed files with 12 additions and 1 deletions
+10 -1
View File
@@ -926,10 +926,19 @@ class ModelsCommand extends Command
$phpdoc->appendTag($tag);
}
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
if ($this->write) {
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
// remove the already existing tag to prevent duplicates
foreach ($phpdoc->getTagsByName('mixin') as $tag) {
if($tag->getContent() === $eloquentClassNameInModel) {
$phpdoc->deleteTag($tag);
}
}
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
}
if ($this->phpstorm_noinspections) {
/**
* Facades, Eloquent API