[8.x] Add invisible modifier for MySQL columns #40002
Merged
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 adds support for the new
invisible
modifier for columns introduced in MySQL 8.0.23: https://dev.mysql.com/doc/refman/8.0/en/invisible-columns.htmlColumns marked as
invisible
are not implicitly selected bySELECT *
and therefore, the columns will also not be automatically hydrated in a Laravel model. Those columns can still be selected explicitly, however, making it useful for columns that contain data that should only be fetched if really needed.A concrete use case might be a model that contains several big JSON structures (e.g. with translation strings in multiple languages), but you only want to select specific keys out of those structures (only translations for the current language and a fallback language, for example). If you always fetched the whole translation structure, a lot of bandwidth and memory are wasted, and you will quickly run into sort buffer limits (which is the main reason why I would love to see this supported).
With this, you can use a new
->invisible()
method on the table Blueprint:This feature is not available in PostgreSQL and I am not aware of any other DBMS supporting this.
I am not sure if you want any modifiers in that are not widely supported, so this is only a suggestion.
However, I do not see an easy way to turn this into a package?