[11.x] Enhance PHPDoc for Eloquent Relations to support precise subclasses #52775
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Currently, all PHPDoc annotations related to Eloquent relations require the native typehint to be declared as
\Illuminate\Database\Eloquent\Relations\Relation
class. This forces users who originally declared more specific relation subclass typehint to change them to the general\Illuminate\Database\Eloquent\Relations\Relation
class.This PR introduces method-scope covariant generics to resolve this issue, allowing PHPDoc to correctly support more specific relation subclass typehint without reverting to the general Relation class typehint.
This change also avoids the usage of
*
to pass meaningless generic parameters for the Relation class, thereby improving the readability and accuracy of the code.@calebdw
Thank you for reviewing this PR. I look forward to your feedback. If there are any further suggestions or concerns, please feel free to reach out.