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

Revolution's avatar

Best Way to Log All DB Queries ? Events or Logs? seeking advice

Wondering if anyone has any quick advice about how to best to track all user CRUD behavior in a searchable, legally-enforceable manner.

Laravel 5.6, Vue 2.x, dealing with protected health info and needing to (most likely) track all changes to models/records. I am not familiar with Slack as a logging solution but understand that I likely need to learn it.

I see that Model Observers may be a good solution. That alone will be a lot of duplication, however, not sure if there's a better way? I'd have a Model Observer for every major model and a lot of duplicate code. Given that there's scaffolding as of maybe 5.3 for Model Observers, I'm assuming that this is the way that the core team is moving things (model boot method for small use cases, model observers on a per-class basis for more formal use cases). Limited documentation yet on best uses of Observers.

Next, I'm not sure exactly what to do from the model events. Should I fire Log entries or maybe record DB events in its own series of tables for capturing crud events? Is firing a DB notification a good method here? My case again is that I have to record the history of every change, who queries and when, all ip hits, etc.

I've been building apps without huge need for events, notifications or logs. I'm just not sure how to best use these 3 major concepts properly. To elaborate, I like the idea of a table or schema that I can query for history as opposed to text-based logs (again noting my ignorance on slack).

Any advice appreciated. Thanks in advance. -Marcus

0 likes
3 replies
shez1983's avatar

spatie has a package that allows you to record any changes. all you need is to pull a trait to your models iirc

i dont think logs are a best place for tracking changes - esp if your admin wants to see them. (and services charging you a lot to keep them for longer periods it might not be the best move)

1 like
Revolution's avatar

@shez1983 Many thanks for the advice. I'll look into that package. Appreciate your response.

Please or to participate in this conversation.