-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] fix: add TPivotModel default and define pivot property in {Belongs,Morph}ToMany #55086
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
Conversation
d82978d
to
bd08fa6
Compare
@@ -20,9 +20,12 @@ | |||
/** | |||
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model | |||
* @template TDeclaringModel of \Illuminate\Database\Eloquent\Model | |||
* @template TPivotModel of \Illuminate\Database\Eloquent\Relations\Pivot | |||
* @template TPivotModel of \Illuminate\Database\Eloquent\Relations\Pivot = \Illuminate\Database\Eloquent\Relations\Pivot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are use cases where project using \Illuminate\Database\Eloquent\Relations\Concerns\AsPivot&\Illuminate\Database\Eloquent\Model
instead of \Illuminate\Database\Eloquent\Relations\Pivot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be necessary to have an interface for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\Illuminate\Database\Eloquent\Relations\Concerns\AsPivot&\Illuminate\Database\Eloquent\Model
is not a correct type because you can't have a trait in a intersection type:
The user just needs to extend from Pivot/MorphPivot
@calebdw does this have any negative affect on PHP Storm and VS Code experience? |
Not that I know of, this should improve the experience as the code now better understands that the |
Thank you sir! |
Hello!
This cleans up the
TPivotModel
implementation in #55053 to use a default so users don't need to set the template if not needed. It also uses the template to define the pivot property on the resultant records.Note that there is currently a PHPStan bug that prevents the TAccessor template from being used as an object key. As soon as that bug is fixed I will submit another PR.
Closes larastan/larastan#1774, closes #55078
CC: @browner12 , @AJenbo
Thanks!