-
Notifications
You must be signed in to change notification settings - Fork 11.4k
[12.x] use "class-string" type for using
pivot model
#55053
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
[12.x] use "class-string" type for using
pivot model
#55053
Conversation
the `using` property of the `BelongsToMany` class is not just a string, but specifically a class string, so we'll document it as such. helps in places where [static methods are being called on the string](https://github.com/laravel/framework/blob/12.x/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php#L160)
apparently can't use Traits as types Co-authored-by: Jeffrey Angenent <1571879+devfrey@users.noreply.github.com>
if someone could point me in the right direction on the generics stuff here, that would be much appreciated. about time I get better at this stuff I guess. |
Looks like the type tests failed. |
@browner12 Take a look at browner12/framework#1 to see if that fixes the tests |
Fixed docblocks for generic to pass type test
thanks @AndrewMast for the fix! |
Is there any benefit to these generics in userland code? Because the new PHPStan supports template defaults, so we could make it optional to provide a more specific class for /**
* @template TPivotModel of \Illuminate\Database\Eloquent\Relations\Pivot = \Illuminate\Database\Eloquent\Relations\Pivot
*/ |
@devfrey indeed. It also broke all my many-to-many relations phpstan.
When adding Pivot to the PHPDoc:
|
This reverts commit 86f8574.
@amants the problem is that Larastan also needs to be updated: https://github.com/larastan/larastan/blob/3.x/stubs/common/BelongsToMany.stub maybe @calebdw can help with this? The default suggested by @devfrey will probably serve to allow it to work with the older Larastan. |
I had thought about something similar to enable the However, the template should use a default to prevent every userland relationship from having to define it |
I updated the stub in Larastan, I have tested that this indeed resolves the issue: larastan/larastan#2231 Having the default there is also enough to avoid having users needing to document it, but it should probably be made a default in both places. |
I'm working on a PR for the framework right now to fix some things with this implementation |
the
using
property of theBelongsToMany
class is not just a string, but specifically a class string, so we'll document it as such.helps in places where static methods are being called on the string
still a little new to the generics declarations, so LMK if I need to adjust anything on that.