# Save the audit trail for your model?

**URL:** <https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226>\
**Category:** Questions\
**Created:** [June 17, 2020, 5:00am UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226 "2020-06-17T05:00:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdo.host](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/abdo.host/32/781_2.png) [@abdo.host](https://discourse.slimframework.com/u/abdo.host)\
**Post date:** [June 17, 2020, 5:00am UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/1 "2020-06-17T05:00:53Z")

</div>

We need make a audit history for any model in your project

How i do this using " illuminate/database " ?

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [June 17, 2020, 5:32am UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/2 "2020-06-17T05:32:24Z")

</div>

Hi @abdo.host What are you trying to log exactly for the audit history? All SQL queries?

---

<div class="post-metadata">

**Author:** ![abdo.host](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/abdo.host/32/781_2.png) [@abdo.host](https://discourse.slimframework.com/u/abdo.host)\
**Post date:** [June 17, 2020, 9:57pm UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/3 "2020-06-17T21:57:56Z")

</div>

i mean create audit history for ( create new or edit or delete )

like this : [https://github.com/owen-it/laravel-auditing](https://github.com/owen-it/laravel-auditing)

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [June 18, 2020, 5:43am UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/4 "2020-06-18T05:43:08Z")

</div>

I’m not sure if it helps. The documentation for Slim 3 contains a receipt for [Eloquent](http://www.slimframework.com/docs/v3/cookbook/database-eloquent.html). You just have to adapt it for Slim 4. If you just want to use the Laravel Query Builder you may look [here](https://odan.github.io/2019/12/03/slim4-eloquent.html). Maybe I write a blog about Eloquent and Slim 4.

---

<div class="post-metadata">

**Author:** ![JustSteveKing](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@JustSteveKing](https://discourse.slimframework.com/u/JustSteveKing)\
**Post date:** [June 18, 2020, 11:19pm UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/5 "2020-06-18T23:19:11Z")

</div>

@abdo.host as you are using Eloquent, you could tap into the model events to queue an insert in model changes? This would probably be the easiest approach as Eloquent Model emit events anyway.

If you are using the DB facade then I would recommend using DB transactions and store the difference.

Obviously there are quite a few ways to achieve this, one I would recommend is a simple event sourcing route.

---

<div class="post-metadata">

**Author:** ![abdo.host](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/abdo.host/32/781_2.png) [@abdo.host](https://discourse.slimframework.com/u/abdo.host)\
**Post date:** [June 20, 2020, 12:53am UTC](https://discourse.slimframework.com/t/save-the-audit-trail-for-your-model/4226/6 "2020-06-20T00:53:28Z")

</div>

How i use Eloquent Event with my model can you make for me a sample one ?
