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

Does 9.0 supports pivot table auditing #506

Closed
PrafullaKumarSahu opened this issue Apr 13, 2019 · 8 comments
Closed

Does 9.0 supports pivot table auditing #506

PrafullaKumarSahu opened this issue Apr 13, 2019 · 8 comments
Assignees
Labels

Comments

@PrafullaKumarSahu
Copy link

Q A
Bug? no
New Feature? yes
Framework Laravel
Framework version 5.6
Package version 9.0
PHP version 7.2.10

Actual Behaviour

  1. I just want to confirm if 9.0 supports auditing of pivots as documentation is still not updated to 9.0?
  2. if yes, will it work with Laravel 5.6?
  3. Is there any simpler way I can achive this with 8.0 and laravel 5.6?
@vpillinger
Copy link

Laravel does not fire eloquent events on pivots in 5.6 so not using the sync() or save() methods on relationships.

There is currently an open pull request in Laravel to do update this, but it will not be until Laravel 5.10 that it is likely released.

You must do 2 steps instead:

  1. Create custom Pivot Model.
  2. Update the pivot model directly instead of using relationship methods.

@PrafullaKumarSahu
Copy link
Author

@vpillinger there is something on laravel 5.8 here > Intermediate Table / Pivot Model Events will this not help auditing?

@jonagoldman
Copy link

Related #58

@PrafullaKumarSahu
Copy link
Author

@jonagoldman so now, if it is dispatching events, in laravel 5.8, we can audit many-to-may relations, right?

@vpillinger
Copy link

Sorry, it appears that in Laravel 5.8 this was indeed updated. The ticket in the Laravel repo was not closed so I did not realize that this was actually done. When I dived the code in 5.8, I did not see the events firing, but better to trust the documentation :).

So all you should need to do is create a custom pivot model and add auditable to it and your good to go.

@PrafullaKumarSahu
Copy link
Author

@vpillinger It will not work for me right now, but as I had noticed you, thought to let you know, nothing else. I will try your solution, what I did is generated another table to get everything recorded and using that to create the report, but I will definitely try your solution and let you know.

@MortenDHansen MortenDHansen self-assigned this Feb 8, 2022
MortenDHansen added a commit that referenced this issue Feb 8, 2022
 + option to supply custom data for new and old on the auditable. This enables registering actions that do not occur through the eloquent events. For example updates on pivot tables
 + Closes issues #657 #636 #628 #597 #591 #506 #496
@MortenDHansen
Copy link
Contributor

v13 supports a way to audit pivots as properties of the auditable itself https://www.laravel-auditing.com/docs/13.0/audit-custom

@jezmck
Copy link
Contributor

jezmck commented Feb 25, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants