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

[9.x] Refactor for missing attributes #44870

Closed
wants to merge 9 commits into from

Conversation

bert-w
Copy link
Contributor

@bert-w bert-w commented Nov 7, 2022

  • Move functionality of [9.x] Opt-in Model::preventAccessingMissingAttributes() option #44283 (Opt-in Model::preventAccessingMissingAttributes() option) to a new trait RestrictsAttributes instead of it being spread out in HasAttributes and Illuminate\Database\Eloquent\Model. This increases modularity greatly and allows developers to use these traits themselves.
  • Make several changes to the HasAttributes trait so it has no dependencies on the RestrictsAttributes trait (that is: functions from this trait have to be checked first using method_exists() before being called. Not having the RestrictsAttributestrait thus reverts the behaviour to before PR [9.x] Opt-in Model::preventAccessingMissingAttributes() option #44283 )
  • Change the order of the if-statement (a && b && c) in throwMissingAttributeExceptionIfApplicable() so it doesn't break on the calls $this->exists && !$this->wasRecentlyMerged since these properties are not part of the trait (and therefore may be undefined depending on where you include this trait). Now, the self::preventsAccessingMissingAttributes() is called first which by default returns false therefore ending the if-statement. This only increases stability since a && b && c can be rearranged in any way, but in this situation there is 1 case that is better being called first.

@bert-w bert-w marked this pull request as ready for review November 7, 2022 18:55
@taylorotwell
Copy link
Member

No tests.

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.

2 participants