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
I have a common Eloquent relationship that I frequently add to many models, so I decided to move this relationship to a trait and include the trait in the models that need it. However, after doing this, the Laravel Idea autocomplete in the editor no longer works.
I have two models, Category and Project, both of which have a parent_id column. The shared relationship is defined in a trait named HasParentTrait, as shown below:
After moving the relationship to the trait, the autocomplete no longer works for methods like with('parent') (e.g., Category::with('parent')) or when accessing the property, like $category->parent->name
I also tried replacing self::class with $this->getModel() in the relationship definition, but the issue still persists.
I hope to fix this bug
Relevant log output
No response
The text was updated successfully, but these errors were encountered:
BassemN
changed the title
[Bug]: Autocomlete for relations from traits
[Bug]: Autocomplete for Eloquent Relationships in Traits Not Working
Oct 5, 2024
It's hard to get the needed class, because Laravel Idea doesn't run PHP. It tried to get everything by parsing your PHP code. I'll try to implement this somehow...
Bug description
I have a common Eloquent relationship that I frequently add to many models, so I decided to move this relationship to a trait and include the trait in the models that need it. However, after doing this, the Laravel Idea autocomplete in the editor no longer works.
Plugin version
8.3.3.242
Operating system
Linux
Steps to reproduce
I created a repository to demonstrate the issue: https://github.com/BassemN/trait-autocomplete. You can find the relevant commit here: BassemN/trait-autocomplete@d8d0186
I have two models,
Category
andProject
, both of which have aparent_id
column. The shared relationship is defined in a trait namedHasParentTrait
, as shown below:After moving the relationship to the trait, the autocomplete no longer works for methods like
with('parent')
(e.g.,Category::with('parent')
) or when accessing the property, like$category->parent->name
I also tried replacing
self::class
with$this->getModel()
in the relationship definition, but the issue still persists.I hope to fix this bug
Relevant log output
No response
The text was updated successfully, but these errors were encountered: