[8.x] Extract attribute getter for performInsert
#36963
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.
With models we disabled
$guarded
or$fillable
and instead opted for a$columns
concept where we define all database columns on the model e.g.This allows us to have a column reference list without having to dig into the database, and also we use this list to filter attributes before saving to avoid some unexpected missing column exceptions when paired with custom properties (after joins etc.). For this to fully work we need to override
performInsert
where instead of$this->getAttributes()
we doWhile we have no problems overriding this, there still is a possibility of a breaking change to occur without us knowing and it'd be safer to manage if the attribute extraction is separated. This also helps us with computed columns where it exists in database as a column but is readonly, in that case we mark it as a comment in the column list.