Open choco-cat opened 1 day ago
This should be:
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
@canvural, I had new docs in #1990 that didn't get merged, can you cherry-pick that? 17bce5f783f19258312aaf8a45e3cbbec335b144
Or just avoid the @return
tag.
Or just avoid the
@return
tag.
The @return
is useful for IDE autocompletion on the method call---and you can avoid a costly model file parse if you include them
This should be:
/** * @return BelongsTo<User, $this> */ public function user(): BelongsTo { return $this->belongsTo(User::class); }
Same error:
/**
* @return BelongsTo<User, $this>
*/
public function third(): BelongsTo
{
return $this->belongsTo(User::class);
}
Method App\Rate\Models\Rate::third() should return Illuminate\Database\Eloquent\Relations\BelongsTo<App\Admin\Models\User, App\Rate\Models\Rate> but
returns Illuminate\Database\Eloquent\Relations\BelongsTo<App\Admin\Models\User, $this(App\Rate\Models\Rate)>.
💡 Template type TDeclaringModel on class Illuminate\Database\Eloquent\Relations\BelongsTo is not covariant. Learn more:
https://phpstan.org/blog/whats-up-with-template-covariant
Make sure to clear any cache, phpstan clear-result-cache
Make sure to clear any cache,
phpstan clear-result-cache
Thanks for this tip, but unfortunately, it didn't solve. Same errors as @koraga
/**
* @return BelongsTo<User, covariant $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
There is no error if I add covariant
Adding covariant
is not the answer
This was working on #1990 (and it is working on my fork). Something likely was messed up when cherry-picking #1990
What does the full Model look like? By any chance are they final
?
What does the full Model look like? By any chance are they
final
?
Yes, all my models are final
Yes, all my models are final
Ah, that's it---I can replicate it now. This looks like a PHPStan bug, I'll open an issue over there
My Models are not final
, but I am getting the same issue.
Description
Hi. How to describe relationships correctly? To my description
an error occurs
Laravel code where the issue was found