Repository navigation
Replies: 4 comments 4 replies
|
@MatthesSt i don't think there is any specific reason why
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}the issue seems to be only with the type definitions / IDE support. laravel handles it correctly at runtime, but static analysis tools don't know that maybe |
|
To summarize and expand on what @nirav-gera explained: Why
|
|
Since your concern is static analysis: Larastan should already type these calls, so if you're getting Why
|
| Setup | Result |
|---|---|
Larastan not included in phpstan.neon (plain PHPStan) |
Call to an undefined method HasMany<Post, Author>::withTrashed(); chaining onward gives mixed |
Relation without generics (no @return HasMany<Post, $this>) |
Call to an undefined method HasMany::withTrashed() |
| Old Larastan / Laravel generics mismatch | Worth ruling out. Larastan 3 expects the two-parameter HasMany<TRelated, TDeclaring> form. |
Also, if the mixed is showing in your IDE rather than in PHPStan output, that's the IDE's own type inference (for PhpStorm, Laravel Idea or the Laravel plugin), not Larastan.
If none of these match, could you share your Larastan, PHPStan and Laravel versions, your phpstan.neon, and the exact dumpType() output? That would help narrow it down.
|
@MatthesSt You are right. This is purely a static analysis / IDE type definition limitation in the framework's docblocks. While Laravel handles To fix this autocomplete and static analysis issue in your local project, the standard community approach is to use the Laravel IDE Helper package. It generates accurate helper files so your IDE recognizes all dynamic scopes:
This will inject the correct |
Uh oh!
There was an error while loading. Please reload this page.
Is there any reason why the morphTo relation is the only relation which type includes the withTrashed() scope even though all relations can apply the scope
All reactions