barryvdh / laravel-ide-helper

IDE Helper for Laravel
MIT License
14.17k stars 1.16k forks source link

"Extended" relationships fails to be recognized #1362

Open HenriqueSPin opened 2 years ago

HenriqueSPin commented 2 years ago

Versions:

Description:

When we "extend# an existing relationship, ide-helper seems to ignore this new relationship.

Let's say we have a relationship like:

 public function allocatedAssets(): HasManyThrough|AllocatedAsset
    {
        return $this->hasManyThrough(
            AllocatedAsset::class,
            Allocation::class,
        );
    }

We want to get only the "open" ones (some filter on the existing relationship):

 public function openAllocatedAssets(): HasManyThrough|AllocatedAsset
    {
        return $this->allocatedAssets()
            ->where(fn($query) => $query->whereNull('arrived_at')->where('will_not_arrive', false));
    }

The above code will not generate the expected docblock lines:

/**
 * @property-read Collection|AllocatedAsset[] $openAllocatedAssets
 * @property-read int|null $open_allocated_assets_count
 */

This way it works:

public function openAllocatedAssets(): HasManyThrough|AllocatedAsset
    {
        return $this->hasManyThrough(
            AllocatedAsset::class,
            Allocation::class,
        )
            ->where(fn($query) => $query->whereNull('arrived_at')->where('will_not_arrive', false));
    }