Skip to content
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.7] Support custom accessor on whenPivotLoaded() #25625

Closed
wants to merge 1 commit into from
Closed

[5.7] Support custom accessor on whenPivotLoaded() #25625

wants to merge 1 commit into from

Conversation

staudenmeir
Copy link
Contributor

@staudenmeir staudenmeir commented Sep 14, 2018

whenPivotLoaded() doesn't work if the relationship uses a custom accessor with ->as('accessor').

You can now specify it as the fourth parameter:

return [
    'expires_at' => $this->whenPivotLoaded('role_user', function () {
        return $this->accessor->expires_at;
    }, new MissingValue, 'accessor'),
];

new MissingValue is necessary as the third parameter ($default = null) because whenPivotLoaded() behaves differently depending on the number of parameters:

'key' => $this->whenPivotLoaded($table, $value)       // "key" missing
'key' => $this->whenPivotLoaded($table, $value, null) // "key": null

I don't think this requires a separate test. The existing one already tests the default pivot accessor.

Fixes #25596.

@sisve
Copy link
Contributor

sisve commented Sep 15, 2018

You're changing a method signature which is a breaking change. This should target the 5.8 release.

@taylorotwell
Copy link
Member

I would also maybe rather add a function like whenPivotLoadedAs($accessor... etc) to make this syntax a little cleaner. But, yes, will probably have to go on master branch. Thanks!

@staudenmeir
Copy link
Contributor Author

@sisve In the past, changes to protected methods haven't been considered breaking.

@sisve
Copy link
Contributor

sisve commented Sep 16, 2018

@staudenmeir Can you give a link that describes when this has happened, and if that decision was intentional or just that no one said anything?

@staudenmeir
Copy link
Contributor Author

@sisve I've seen multiple cases, but I can't find one right now. I can't remember an explicit "protected methods can be changed" comment, so they could have been mistakes.

@staudenmeir
Copy link
Contributor Author

@sisve I found an example: Taylor renamed a protected method in 9a912d6.

@sisve
Copy link
Contributor

sisve commented Sep 18, 2018

It's hard to provide any argument other than the linked commit was not part of a PR, and was not reviewed by anyone. Someone would have to read every commit to catch these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants