Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SirPoot's avatar
Level 22

Laravel Auditing

I am looking to deploying auditing in one of my Laravel applications.

My application downloads data from a 3rd party party API and saves it locally. In the event, it is going to update a record (say an account), I would like that the "old" data to be saved for historical purposes while keeping the latest data in the table.

I've narrowed my search down to two packages; laravel-activitylog and laravel-auditing. I love what spatite has done for the community and the amount of packages he has developed. I am leaning toward laravel-auditing because I really like the audits Eloquent relationship.

laravel-activitylog - https://docs.spatie.be/laravel-activitylog/v2 laravel-auditing - http://www.laravel-auditing.com

I wanted to put this out there and get some feedback.

Have you used either package? What were your thoughts? Is there a package I missing? Am i going about this auditing the right way? Is there a better way?

0 likes
5 replies
developer1237's avatar

Laravel-activitylog by spatie is awesome.But you may also create your custom activity logs much faster,better,flexible using cool eloquent as you want as per your use cases/ requirements. Happy coding !! :)

1 like
Cronix's avatar
Cronix
Best Answer
Level 67

I do something similar except I use mysql database triggers. Whenever something gets updated, it copies the old data to a history table before the new data gets updated. It's very fast because, like a stored procedure, it lives IN the database and is automatic. You can create different triggers for insert/update/delete events (think of it like a laravel database event).

No package will be as fast (or as easy) as a native trigger.

Then I just create a 'history' relationship for those tables that have the triggers, so I can just do Model::with('history')->get().

https://dev.mysql.com/doc/refman/5.7/en/triggers.html

https://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html

2 likes
kalvinmizzi's avatar

@Cronix How will this work with bulk queries where you are updating 1000 records at a time? With spatie's package since we won't be hitting eloquent, we can do a custom log with just a single record for all 1000 records. With it tied to the database wouldn't it trigger automatically with all that data?

1 like
SirPoot's avatar
Level 22

Thank you @Cronix for broadening my view. I was thinking about this initially and then tunnel vision set in. I believe this will be the way I am going to go.

Please or to participate in this conversation.