Laravel Auditing — simple way to track your application

Petar Harizanov
2 min readOct 7, 2019

Soo Laravel Auditing… this amazing package is probably one of the best tools for monitoring your php application data. In this quick medium story, I will not gonna describe the process of integrating the package to your project, but rather why I think you should use this package. Probably this will be your last drop of motivation, that you need.

You can read the official documentation here. It covers everything from the installation to the advanced usage. It’s written pretty intuitively and probably can be integrated just in a matter of minutes.

In a nutshell, this package will create for you a table named “audit”, which will contain all of the needed information for tracking an entity change. So on different events like [created, updated, deleted and restored], a new entry will be created. It will contain the user, which altered the record, along with the model itself and its changes. You will also receive some helpful information like URL, IP address, user agent and tags.

To start using the library, you just need to implement the Auditable contracts to the model that you want to track. It can’t be more simple than that, believe me.

Apart from the easy setup, that package will give you big flexibility. So let's go through some of the points.

Migrations

Sometimes the default package table schema is not suitable, luckily there is a simple way to make some customization here. You just need to apply some of the changes to the config file and you’re good to go.

Resolvers

Through the resolvers you can specify how the data will be handled before is written in the “audit” table. You can change basically the User, User-Agent, IP Address, and the URL. For example, if you run your app behind load balancer the IP must be obtained a bit differently. So the IpAddressResolver is perfect for that.

Tags

I think that you’ll love this one. It gives you a convenient way of filtering the data. You just specify the tags on a model level and from there on they will be written on the audit table.

When your application grows with the time, such a package is a must-have. The best thing is that when you need this functionality you can just start using Laravel Auditing right away and you will get a lot of features out of the box.

--

--

Petar Harizanov

Web developer, entrepreneur, and a former digital agency owner. Personal website: www.pharizanov.com