-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Make it easier to extend relationship classes #22382
Conversation
…sses from this array
I like the concept, but I would rather have it on a |
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
use Illuminate\Database\Eloquent\Relations\HasManyThrough; | ||
use Illuminate\Database\Eloquent\Relations\MorphToMany; |
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.
Imports should be sorted by length. Helps review the PR.
@deleugpn I am not sure what are you mean. But I only can do something like this :
is this what you want ? |
Instead of |
@deleugpn newHasOne, newBelongsTo ... or 2.something like :
|
One for each. |
If you mean like this : 1 .
then ok, but if you mean like this: 2 .
is not ok for me because laravel have different argument count and types of relations between versions, and then I anyway must change newBelongsToMany() function for each laravel version what is not the goal. My idea is just to tell laravel which class should use for relation instance not define how the instance is created. I am a little bit skeptical because I can't find the example of the first way in laravel code, but I can find the second one... What is the procedure now I should create new PR or I can commit to this one? |
@deleugpn any news on this? another example: in this package, I extended "BelongsTo" and "HasOne" relations with current laravel core code, I have to have the separate branch for each laravel version (5.2 5.3 .5.4 5.5) with my PR I could have only one branch for all laravel versions. It gets more complicated if I want to use more packages that extend the same relation, but with this PR, it could be much simpler, elegant and better. |
If the arguments change between versions you are going to have to update your code anyways? Right? |
@taylorotwell If I could just define which class laravel should use then no if I have to define how this class should be created then yes.
vs
|
I agree with Taylor. Both solution are exactly the same. The difference is that one uses an array and instantiate a magic variable and the other offers a method for you to override. |
Going to hold off on this for now. I'm open to seeing the method based approach to see if I like it a bit better. |
Will try to pick this up after the holidays. |
what is new in this PR
with this PR we can easily change relationship classes
"imports", "classes array" and "method in a class" now have the same order :
https://github.com/fico7489/laravel-pivot/blob/master/src/Traits/ExtendBelongsToManyTrait.php
with my change It will be just
and this is really awkward, especially if you have a different branch for each laravel versions because these relationship methods are different for each laravel version. Also, I see that many people want to extend relationship classes in packages and this PR will help them with that.
Solution is not fancy with interfaces and patterns but is better than the current.