laravel-idea/plugin

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

Opened this issue · 0 comments

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