Jonjie's avatar
Level 12

Tracking changes package for laravel

Hi. Just thinking what's the best package I should use to log all the changes made my admin in the database like create, update, delete?

  1. I also see this package, would you recommend this? http://www.laravel-auditing.com/docs/9.0/model-setup
  2. Do you recommend to use a package, or just create my own functionality?

PS Haven't tried this feature before. I'm using laravel 7.

0 likes
4 replies
alanholmes's avatar

Hi @jonjie

I would definitely recommend using a package like the one you have found, over creating your own.

Personally, I replaced the one you found with https://spatie.be/docs/laravel-activitylog/v3/introduction in my application, for one pure reason, the Spatie one gives you the option of also manually logging entries to the log table.

Which I use to log changes to pivot tables against the record changed

Jonjie's avatar
Level 12

@alanholmes Nice :) Can I also change it to save it as a file instead of saving to the database? Or it is better to save on the DB? I'm thinking when my database got down, I still have the log file.

Also, can I add custom column like ip_address?

alanholmes's avatar
Level 35

Hi @jonjie

Im not sure about the auditing pacakge you mentioned, but the Spatie one seems very much based on being a databse.

Though, it does have a config option/env var for setting a database connection if you wanted to keep it separate from the main database (not 100%, but you might be able to do it as an sqlite connection type - which would give you a file).

As for custom columns, you can add them as custom property: https://spatie.be/docs/laravel-activitylog/v3/basic-usage/logging-activity#setting-custom-properties Which I believe is stored as a JSON field, so it can be anything really.

And for adding them to the model events, you can add a tapActivity() method on the model to do this https://spatie.be/docs/laravel-activitylog/v3/advanced-usage/logging-model-events#tap-activity-before-logged-from-event

Please or to participate in this conversation.