[7.x] Simplify hidden attributes on models#30348
Merged
taylorotwell merged 2 commits intolaravel:masterfrom Oct 21, 2019
Merged
[7.x] Simplify hidden attributes on models#30348taylorotwell merged 2 commits intolaravel:masterfrom
taylorotwell merged 2 commits intolaravel:masterfrom
Conversation
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is aimed to make the method behaviour more predicatable, consistent and to slightly simplify the codebase.
The state before this PR is the following:
makeHiddenandmakeVisibleare featured on documentation and tested,addHiddenandaddVisibleare not. And each ofadd*only has a single use in the codebase.makeHiddenmay produce surprising results on an edge case:makeHidden['col1']on a model that has$visible = ['col1']would clear (and thus disable) the whitelist, making everything visible (exceptcol1).addVisiblemay produce unexpected results on two cases$visiblewas empty,addVisible('col1')will make everything butcol1invisible;col1is hidden,addVisible('col1')would not make it visible.makeHidden/makeVisibleandaddHidden/addVisibleare just these:make*returns model,add*returns void.add*accepts unwrapped lists of arguments('col1', 'col2')in addition to single string('col1')and arrays(['col1', 'col2'])which are accepted by both.To solve the inconsistencies and surprises, simplify the work with the methods and reduce amount of similar methods, I propose here to:
makeHiddenandmakeVisibleaccept unwrapped lists of arguments('col1', 'col2')in addition to current('col1')and(['col1', 'col2']). That's for convenience and consistency with methods likewith().addHiddenandaddVisible.addVisiblelogic intomakeVisible(it's still one line).makeHiddento only add entries to$hidden, but not remove the from$visible.Explanation on the final point: adding to blacklist
$hiddenis enough as the blacklist is applied last. The only case where removing from$visiblewould affect behaviour is the aforementioned quirk that makes everything else visible and such behaviour just shouldn't be here.