Fix disable auditing before model initialization #758
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.
The
Auditable::bootAuditable()
trait loader on the model works only once, at the very first initialization of the class. Thus, at the moment, if auditing is disabled on the model during initialization, an observer will not be booted on the model, and a further call toModel::enableAudit()
will not change anything - there is no observer, no events are registered.The
itDisablesAndEnablesAuditingBackAgain
test skipped this behavior because the model was first initialized before auditing was disabled.I suggest init observer on the model, regardless of the
$auditingDisabled
flag. I made the appropriate changes, and theitDisablesAndEnablesAuditingBackAgainViaFacade
test, where auditing is disabled before initialization.