Closed rcerljenko closed 3 months ago
@rcerljenko,
Thanks for reporting! However, this error is correct---there is no way for static analysis to determine what models can actually be returned, so the ->morphTo()
method always returns MorphTo<Illuminate\...\Model, $this>
(notice that this method does not accept a class string like other relation methods).
Your options are:
HasNotifications&Model
is returned from the relation---you could potentially have an IlluminateModel returned which could break your code.->getKey()
, ->getAttribute()
instead of property access, etc.) or you will need to narrow the type assert($model instanceof HasNotifications)
Let me know if you have any questions or need help with specific examples!
Description
Hi,
First of all many thanks for your efforts and this fork! I have a question regarding eloquent relations feture that you've added in this fork. Everything works great but I can't seem to make phpstan work with MorphTo relation.
This is the issue that I'm getting:
Laravel code where the issue was found
HasNotifications - a contract Model - custom model class which extends Laravel Eloquent Model