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

Feature request: add support for detecting generic relation type for PendingHasThroughRelationships #1550

Open
jnoordsij opened this issue Feb 16, 2023 · 0 comments

Comments

@jnoordsij
Copy link

  • Larastan Version: 2.4.0
  • --level used: 6

Description

In laravel/framework#45894 a new PendingHasThroughRelationship was introduced to allow for easier through-relation building.

However, when using these relations in my application, I was faced with the following error:

 ------ -------------------------------------------------------------------------------------------------------
  Line   app\Models\BaseModel.php
 ------ -------------------------------------------------------------------------------------------------------
  x      Parameter #1 $callback of method Illuminate\Database\Eloquent\PendingHasThroughRelationship::has()
         expects (callable(Illuminate\Database\Eloquent\Model):
         Illuminate\Database\Eloquent\Relations\HasMany|Illuminate\Database\Eloquent\Relations\HasOne)|string,
         Closure(App\Models\ThroughModel):
         Illuminate\Database\Eloquent\Relations\HasMany<App\Models\RelatedModel> given.
 ------ -------------------------------------------------------------------------------------------------------

Laravel code where the issue was found

See also the PR mentioned above

class Project extends Model
{
    public function deployments()
    {
        return $this->through($this->environments())
            ->has(fn (Environment $env) => $env->deployments());
    }

    public function environments()
    {
        return $this->hasMany(Environment::class);
    }
}

class Environment extends Model
{
    public function deployments()
    {
        return $this->hasMany(Deployment::class);
    }
}

class Deployment extends Model
{
    //
}
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

1 participant