-
Notifications
You must be signed in to change notification settings - Fork 391
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
Automatic auditing of attach/detach for BelongsToMany #869
Comments
And It would also be a breaking change, because everyone should already be using |
What do you mean? I meant: If you want to audit specific relationship attach/detachments, you can implement it in the main point where your intention to audit lies, not at various points in your existing codebase. In the documented manner you'd have to change all calls from $model = MyModel::factory()
->hasAttached($otherModel)
->create(); In the proposed solution this will get audited. I call that automated. I think I forgot sync, which can be simply added. I'd have to check if MorphToMany can be an argument to @parallels999 thanks for your cheerfulness about this issue 😉 |
I think it's a great idea, but you could no longer decide if you want to audit only the id column return BelongsToManyAudit::audit($this->belongsToMany(OtherModel::class), [
'audited_column_1', 'audited_column_2'
]); |
I see the idea. Might need to think a bit though. At first i was reluctant to make the relations audit because the whole concept is basically to audit by the events (audit by model). Using the custom audit is a way to get the job done when you attach a role to a user (or similar), and the supplied methods are basically just a documented workaround for the missing events. The manual effort of explicitly using the auditSync/attach/detach front methods are actually quite intentional so that it is only used deliberately. |
Also #873 would be needed |
Side note, aren't these only for morphs right now? The only doc I find on these functions is in relation to morphs |
@nikspyratos |
To audit attach and detach at the moment you'd have to call Auditable::auditAttach or Auditable::auditDetach. I have a solution to audit the attach/detach while the normal methods are called.
Would you be interested into a PR with this solution?
It works as follows:
The text was updated successfully, but these errors were encountered: