Open makroxyz opened 4 days ago
Hello!
Thanks for your report, however, this is expected as closure parameter types are invariant. See:
I thought this would be fine since most methods you need are defined on the Relation but morphWith
is only defined on the MorphTo
relation so you do need to type it.
I'll open an issue with PHPStan to see if there's a way to solve this problem. In the meantime you can override the type inside the closure:
$resources = Resource::query()
->whereIn('resource_id', $requestResources)
->with([
'monitorable' => function ($morphTo) {
/** @var MorphTo $morphTo */
$morphTo->morphWith([
Service::class => ['relation1', 'relation2'],
]);
},
]);
Sorry, but workaround doesn't work...
PHPDoc tag @var for variable $morphTo contains generic class Illuminate\Database\Eloquent\Relations\MorphTo but does not specify its types: TRelatedModel, TDeclaringMode
So then use:
/** @var MorphTo<*, *> $morphTo */
Description
Starting from Laravel 11.23.* the following error
Laravel code where the issue was found