-
Notifications
You must be signed in to change notification settings - Fork 394
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
Laravel 5.6 pivot table auditing using laravel auditing 8.0 #507
Comments
Just fire the appropriate events manually and pass the Pivot object to the Auditor. You can create audit records following this documentation: http://laravel-auditing.com/docs/9.0/auditor The key line being |
@vpillinger thank you for your kind reply, I tried implementing that, but still could not make it work, let me share the changes I have made. In config/audit.php
and in pivot auditable trait
In composer.php
and in my controller
|
Hy @vpillinger I am also needing this function. can you explan how you use, please? |
I tried to make work, but give up. but I find a beter pakage https://altek.gitlab.io/accountant |
This is designed for restricting audit events, not adding new ones. You don't need new events here.
I have not really looked at this class too closely, but you don't need this. Instead, you just want to add Auditable to the Pivot Class and use the existing functionality:
Now, syncing doesn't fire an updated event in older versions of Laravel. Therefore, you need to fire the updated event manually or create the audit yourself. What you did is fire the event on $video, but you want to fire the event on the pivot.
Now your original code has a couple issues which I think that your running into trouble with this in the first place.
As far as I can tell, you were trying to do something like:
|
@vpillinger, thank you so much for your kind reply. Re: 1. video has multiple statuses because parallelly we are performing multiple operations, so based on different operation video has multiple statuses at the same time. Re: 2. if I want to update a pivot record with this video id and this status, how I should update that as |
A good use for a custom column on a pivot table is something like: video_id In this case, an access_permission is some additional value that is inherent to the relationship. In your case, it sounds like you are ending up with this: video_id At this point, you are not really working with a pivot anymore, but a completely new concept like an So it overall sounds like your doing something wrong with your architecture that is causing the pivot issue in the first-place. Regarding your question on |
no, I am ending up with |
closed due to inactivity |
Steps to Reproduce
As there is no event fired for attach, detach and sync, Laravel auditing does not store records for these operations, but for my requirement, I need to store this, so I tried to follow some solutions provided in git issue discussion, but could not achieve it.
The most important thread was this pull request. After going through this I tried to implement this gist solution. but I am unable to log it in audits_pivot table.
Any help on this will be appreciated.
The text was updated successfully, but these errors were encountered: