Skip to content
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

[Bug]: Autocomplete for Eloquent Relationships in Traits Not Working #1079

Open
BassemN opened this issue Oct 5, 2024 · 1 comment
Open

Comments

@BassemN
Copy link

BassemN commented Oct 5, 2024

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 and Project, both of which have a parent_id column. The shared relationship is defined in a trait named HasParentTrait, as shown below:

    public function parent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(self::class, 'parent_id');
    }

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

@BassemN BassemN changed the title [Bug]: Autocomlete for relations from traits [Bug]: Autocomplete for Eloquent Relationships in Traits Not Working Oct 5, 2024
@adelf
Copy link
Member

adelf commented Oct 10, 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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants