Published on

Masonite Audit


Getting Started

Install the package using pip:

pip install masonite-audit

Add AuditProvider to your project in config/

# config/
# ...
from masonite_audit import AuditProvider

# ...
    # ...
    # Third Party Providers
    # ...

Publish the package configuration files.

python craft package:publish masonite-audit

This will add migrations and other masonite-audit related configuration to your project. Run your migrations to create the related database tables.

python craft migrate

Finally, inherit Audit mixin into all the models for which you need audit logging.

from masonite_audit.mixins import Audit
class YourModel(Audit):

If you want to get the audit history for a model, you can use the history method:

user = User.find(1)

In order to rollback to previous versions of a model, you can use the rollback method:

user = User.find(1)
user.rollback() # to rollback to previous version
# or
user.rollback(step=4) # to rollback to version 4