Record the change log from models in Laravel

Overview

Build Status Code Coverage Latest Stable Version Total Downloads License Chat

This package will help you understand changes in your Eloquent models, by providing information about possible discrepancies and anomalies that could indicate business concerns or suspect activities.

Laravel Auditing allows you to keep a history of model changes by simply using a trait. Retrieving the audited data is straightforward, making it possible to display it in various ways.

Official Documentation

The package documentation can be found on the official website or at the documentation repository.

Version Information

Version Illuminate Status PHP Version
12.x 6.x.x - 8.x.x Active support 🚀 >= 7.3 | 8.0
11.x 5.8.x - 8.x.x Active support >= 7.3
10.x 5.8.x - 7.x.x Active support >= 7.2.5
9.x 5.8.x - 6.x.x Active support >= 7.1.3
8.x 5.2.x - 5.7.x Active support >= 7.0.13
7.x 5.2.x - 5.6.x End of life >= 7.0.13
6.x 5.2.x - 5.6.x End of life >= 7.0.13
5.x 5.2.x - 5.5.x End of life >= 7.0.13
4.x 5.2.x - 5.5.x End of life >= 5.5.9
3.x 5.2.x - 5.4.x End of life >= 5.5.9
2.x 5.1.x - 5.3.x End of life >= 5.5.9

Contributing

Please see the contributing entry for more details.

Credits

License

The Laravel Auditing package is open source software licensed under the MIT LICENSE.

Comments
  • Not logging Affected Relations?

    Not logging Affected Relations?

    Is it correct that any updated relations are not being logged in the database? I'm using eloquent's sync() function a lot, for updating many-to-many relations...

    Any ideas how to do that?

    enhancement help wanted 
    opened by bbredewold 96
  • Support Laravel 6.0

    Support Laravel 6.0

    | Q | A | ----------------- | --- | Bug? | no | New Feature? | yes | Framework | Laravel | Framework version | 6.0 | Package version | 9.2.0 | PHP version | 7.3

    Actual Behaviour

    I can't upgrade to Laravel 6.0 because owen-it/laravel-auditing v9.2.0 requires illuminate/filesystem ^5.8

    Expected Behaviour

    Upgrading to 6.0

    Steps to Reproduce

    • Update laravel/framework to 6.0
    • composer update
    opened by forestia-dev 37
  • Log - messages

    Log - messages

    @devthiagolino Os meus logs aparecem assim:

    user.name atualizou os dados de SANTA CATARINA1 De: old.uf -> Para: new.uf updated in 2015-10-02 02:33:45 De: SANTA CATARINA -> Para: SANTA CATARINA1 updated in 2015-10-02 02:33:45 user.name atualizou os dados de SANTA CATARINA De: old.uf -> Para: new.uf updated in 2015-10-02 11:01:41 De: SANTA CATARINA1 -> Para: SANTA CATARINA updated in 2015-10-02 11:01:41

    2 duvidas por mais obvias pois estou comecando a utilizar o laravel:

    1. Por que ao inves do nome do usuario aparece user.name ? Tenho que fazer um relacionamento das tabelas logs e users ?
    2. Como suprimir os logs onde old.campo e new.campo são nulos ?
    opened by edukmattos 30
  • Trait 'OwenIt\Auditing\AuditingTrait' not found

    Trait 'OwenIt\Auditing\AuditingTrait' not found

    A aplicação funciona perfeitamente em ambiente de desenvolvimento, subo para o servidor de produção, rodo a migrate e nada! Trait 'OwenIt\Auditing\AuditingTrait' not found

    opened by wallauschek 30
  • question about contracts & implementation

    question about contracts & implementation

    • isnt it possible to just use the package by simply including the trait ? why do i have to implements AuditableContract for every model ?

    • for user model

    'user' => [
            'primary_key' => 'id',
            'foreign_key' => 'user_id',
            'model'       => App\User::class,
            'resolver'    => App\User::class,
        ],
    

    it should be enough setting a model value and then the package gets it and do its ops internally, this now removes the steps of having to implements UserResolver & manually adding

    public static function resolveId()
        {
            return auth()->check() ? auth()->user()->getAuthIdentifier() : null;
        }
    
    invalid 
    opened by ctf0 22
  • Added a filesystem driver

    Added a filesystem driver

    This is being submitted as a preliminary request for comments. It is currently functional, both with local and remote disks, but I'm open to suggestions for improvements.

    opened by ymslavov 21
  • Can't get Audit Users when User Model uses non-default Primary Key

    Can't get Audit Users when User Model uses non-default Primary Key

    | Q | A | ----------------- | --- | Bug? | yes | New Feature? | no | Framework | Laravel | Framework version | 5.4.25 | Package version | 4.0.7 | PHP version | 7.0.18

    Actual Behaviour

    It is not possible to get a Model Audit's User if the User Model uses a non-default Primary Key (ie. a Primary Key different than id).

    Expected Behaviour

    It should be possible :-)

    Steps to Reproduce

    • Setup Laravel and Auditing.
    • Change the App\User model's Primary Key to something else (like some_id) both in the Model (via the protected $primaryKey property) and the database.
    • Add an auditable model:
    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    use OwenIt\Auditing\Auditable;
    use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
    
    class SomeModel extends Model implements AuditableContract
    {
        use Auditable;
    
        public $timestamps = false;
    
        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'field1', 'field2', 'field3',
        ];
    }
    
    • Add a table for the new model with a migration with:
    Schema::create('some_models', function (Blueprint $table) {
            $table->increments('id');
            $table->string('field1');
            $table->string('field2');
            $table->string('field3');
        });
    
    • Run a simple test like:
    public function testAudits()
    {
        $modelFields = [
            'field1' => 'Field '.rand(),
            'field2' => 'mail'.rand().'@mail.com',
            'field3' => 'password'.rand(),
        ];
    
        $model = new SomeModel($modelFields);
    
        // set a proper ID in here
        Auth::onceUsingId(1);
        $model->save();
    
        // get model with audits and users
        $model = SomeModel::with('audits.user')->find($model->getKey());
    
        echo "model: \n";
        print_r($model->attributesToArray());
    
        $audit = $model->audits->first();
    
        echo "audit: \n";
        print_r($audit->attributesToArray());
    
        $user = $audit->user;
    
        echo "user: \n";
        print_r($user->attributesToArray());
    }
    

    Result:

    1) Tests\Unit\SomeModelTest::testAudits
    Error: Call to a member function attributesToArray() on null
    

    (on the print_r($user->attributesToArray()); line)

    Possible Solutions

    I got it working by adding a 'user_id' parameter to the Audit::model() method so it looks like:

    public function user()
    {
        return $this->belongsTo(Config::get('audit.user.model'), 'user_id');
    }
    
    bug enhancement 
    opened by ghost 20
  • Added (optional) morphable user

    Added (optional) morphable user

    Changes

    • Added config option for morphable mode. Everything defaults to 'single mode', to maintain backwards compatibility.
    • Added config option for guard order.
    • Changed current UserSolver to UserIdSolver.
    • Added UserIdSolver and UserClassSolver.
    • Added commented value to migration file, which needs to be uncommented for morphable to work.
    • Added tests to include new classes.
    • Adjusted tests to test both modes.
    opened by crashkonijn 16
  • Q: Best practices for restoring previous state of Auditable model

    Q: Best practices for restoring previous state of Auditable model

    | Q | A | ----------------- | --- | Bug? | no | New Feature? | probably | Framework | Laravel | Framework version | 5.5.17 | Package version | 4.1.3 | PHP version | 7.1.4

    Question

    Is there a halfway elegant way for programmatically restoring an old state (i.e. using e.g. the third Audit of a model and applying its diff to the model), like either a Laravel framework or an Auditing function?

    I'm looking to do something like:

    $user->rollback($user->audits->first());
    

    or

    $user->rollback(Carbon::createFromDate($year, $month, $day));
    

    If not, would the maintainers consider this a core function of this package or should it be put into an external library?

    opened by Harti 16
  • How to auditrail Delete with composite key

    How to auditrail Delete with composite key

    | Q | A | ----------------- | --- | Bug? |yes | New Feature? | no | Framework | Laravel|Lumen | Framework version | 5.6 | Package version | 8.0 | PHP version | 7.2.8

    Actual Behaviour

    I want to audit if i delete the model with composite key in Model:
    protected $primaryKey = ['roleID', 'menuPermissionID']; public $incrementing = false;

    using model: $result = $this->model->where('roleID',$roleId)-> where('menuPermissionID',$menuPermissionID)>firstOrFail(); $result->delete();

    Expected Behaviour

    it should delete and save to audit trail. right now there is an error during delete. however if i used this query $this->model->where('roleID',$roleId)->delete(); it will delete but it won't audit trail. current error: array_key_exists(): The first argument should be either a string or an integer

    duplicate V6 
    opened by caranzojason 15
  • Updated command do not record in audits table

    Updated command do not record in audits table

    Hi, Im using Laravel 5.2 and Auditing 3.1.
    When updating a post, only the USERS table writes the UPDATED action. The other tables do not. Below are sample images:

    My USER model - UPDATED works fine captura de tela 2017-02-15 as 18 44 06

    My NEWS Model - UPDATED do not record in audits table: captura de tela 2017-02-15 as 18 46 41

    duplicate 
    opened by rafalau 15
  • SoftDelete problem

    SoftDelete problem

    | Bug? | no|yes | New Feature? | no|yes | Framework | Laravel | Framework version | 8 | Package version | 13 | PHP version | 8

    Actual Behaviour

    hi, i need some help, i'm trying to make a custom Audit model to add the sofdeleted models, but it doesn't work may i made any mistakes. first i copied the Audit.php model of the package and then i did the implementation on my app\config.php, but anyway it doesn't work. i read the doc for the softdelete but for me isn't so clear and i can't make it work :( the only solution to my problem at this moment is adding ->withTrashed() to functions in trait in the vendor folder, but i'd like to avoid that.

    Expected Behaviour

    i've read that the functions would be added to the model and not to the trait, but in my package (v.13) is still in the trait

    Possible Solutions

    make the documentation for implementing the softdelete easier

    if anyone can help, thanks

    opened by RobTDE 0
  • Revert to specific version

    Revert to specific version

    Hi guys, can somebody help me with this issue? If I give the transitionTo function an audit before let's say 3 versions, then it only applies the changes from version 3 and not also from 0,1 and 2. That would be annoying if you had to manually apply all the "between"-changes. Or did I missed something here? I assumed that the package does this automatically? If I want to revert to a specific version, with all changes made till then, do I need to iterate through all the audits and apply the changes manually?

    opened by Sairahcaz 0
  • Manual audit

    Manual audit

    It's not a bug

    Is it possible to make a manual audit?. I have a lot of funcitons on my model observer, and i need to audit when i execute update in quietly mode. Is it possible?

    Thanks

    opened by xavicabot 0
  • Laravel Auditing Package Unicode Format Issue

    Laravel Auditing Package Unicode Format Issue

    I have installed Laravel Auditing package, now when i insert or update data in Unicode format it store in database like: {"name":"\u0627\u062d\u0645\u062f\u0627\u0644\u0644\u0647","email":"[email protected]","branch_id":"1","id":20}

    opened by qalildarwish 0
  • Enabling

    Enabling "Strict Mode" on Eloquent Model

    When enabling strict mode: https://laravel.com/docs/9.x/eloquent#configuring-eloquent-strictness

    Model::shouldBeStrict(! $this->app->isProduction());

    It will print an error:

    The attribute [auditEvents] either does not exist or was not retrieved for model [App\Models\User].

    image

    opened by simonmaass 6
Releases(v13.0.5)
  • v13.0.5(Jul 29, 2022)

    What's Changed

    • Fix attributes with enums being excluded from audit by @mogottsch in https://github.com/owen-it/laravel-auditing/pull/723
    • Restore Lumen support by @erikn69 in https://github.com/owen-it/laravel-auditing/pull/731

    New Contributors

    • @mogottsch made their first contribution in https://github.com/owen-it/laravel-auditing/pull/723

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v13.0.4...v13.0.5

    Source code(tar.gz)
    Source code(zip)
  • v13.0.4(Jul 14, 2022)

    What's Changed

    • Deprecated config causes errors by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/696
    • User morph prefix from config on migration by @erikn69 in https://github.com/owen-it/laravel-auditing/pull/719
    • Use configured db connection in default migration by @joe-pritchard in https://github.com/owen-it/laravel-auditing/pull/727

    New Contributors

    • @joe-pritchard made their first contribution in https://github.com/owen-it/laravel-auditing/pull/727

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v13.0.3...v13.0.4

    Source code(tar.gz)
    Source code(zip)
  • v13.0.3(Apr 21, 2022)

    What's Changed

    • Reset isCustomEvent flag after attach/detach/sync events by @zoispag in https://github.com/owen-it/laravel-auditing/pull/701
    • fixed UserResolver (fixes #704) by @edvordo in https://github.com/owen-it/laravel-auditing/pull/705
    • Add option to skip auditSync when sync has no changes by @mitchdesign in https://github.com/owen-it/laravel-auditing/pull/707
    • Minor revisions by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/713

    New Contributors

    • @zoispag made their first contribution in https://github.com/owen-it/laravel-auditing/pull/701
    • @edvordo made their first contribution in https://github.com/owen-it/laravel-auditing/pull/705
    • @mitchdesign made their first contribution in https://github.com/owen-it/laravel-auditing/pull/707

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v13.0.2...v13.0.3

    Source code(tar.gz)
    Source code(zip)
  • v13.0.2(Mar 15, 2022)

    What's Changed

    • $auditEvent from protected to public to make AuditCustom possible by @r0lodex in https://github.com/owen-it/laravel-auditing/pull/699
    • add test for custom events (pr #699) by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/700

    New Contributors

    • @r0lodex made their first contribution in https://github.com/owen-it/laravel-auditing/pull/699

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v13.0.1...v13.0.2

    Source code(tar.gz)
    Source code(zip)
  • v13.0.1(Mar 9, 2022)

    What's Changed

    Default guards as defined in the distributed config does not comply with all supported laravel versions. Instead of changing and risking break of older installations, guards are now skipped if they can't be resolved.

    • Fix README.md by @erikn69 in https://github.com/owen-it/laravel-auditing/pull/693
    • Default user guard by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/695

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v13.0.0...v13.0.1

    Source code(tar.gz)
    Source code(zip)
  • v13.0.0(Mar 2, 2022)

  • v12.2.1(Feb 23, 2022)

    What's Changed

    • Update composer.json by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/687
    • Add audit exclude test by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/690
    • Update README.md by @erikn69 in https://github.com/owen-it/laravel-auditing/pull/686
    • Dont publish migration if migration exists by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/692 (thanks to @corbancode pr #644)

    New Contributors

    • @erikn69 made their first contribution in https://github.com/owen-it/laravel-auditing/pull/686

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v12.2.0...v12.2.1

    Source code(tar.gz)
    Source code(zip)
  • v12.2.0(Feb 7, 2022)

    Date serialization happens through the auditable model - Thanks to @bskl

    What's Changed

    • Use date serialization from auditable by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/683
    • Makes Audit interface compatible with Laravel and MongoDB by @claudsonm in https://github.com/owen-it/laravel-auditing/pull/618

    New Contributors

    • @claudsonm made their first contribution in https://github.com/owen-it/laravel-auditing/pull/618

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/12.1.0...v12.2.0

    Source code(tar.gz)
    Source code(zip)
  • 12.1.0(Feb 2, 2022)

    • Added Laravel 9 support
    • Fixes issue with Laravels AsArrayObject cast which would cause getModified to display wrong output

    A number of adjustments to the project testsuite and repository

    What's Changed

    • Apply fixes from StyleCI by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/676
    • Add test-matrix for versions supported by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/678
    • Fix: Disable audits with config even if is running on console by @marcoocram in https://github.com/owen-it/laravel-auditing/pull/583
    • add config for api guard by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/679
    • 12.1.0 dev by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/675
    • Laravels arrayObject cast does not take passed value by @MortenDHansen in https://github.com/owen-it/laravel-auditing/pull/680

    New Contributors

    • @MortenDHansen made their first contribution
    • @marcoocram made their first contribution

    Full Changelog: https://github.com/owen-it/laravel-auditing/compare/v12.0.0...12.1.0

    Source code(tar.gz)
    Source code(zip)
  • v12.0.0(Dec 15, 2020)

  • v11.0.0(Sep 14, 2020)

    Laravel 8 Compatibility

    Includes :

    • PHP version bump;
    • Change usage of deprecated $app;
    • Updated readme and travis/scrutinizer;
    • Config updated.
    Source code(tar.gz)
    Source code(zip)
  • v10.0.0(Mar 23, 2020)

  • v9.3.0(Sep 11, 2019)

  • v9.2.0(Apr 11, 2019)

  • v9.1.0(Apr 11, 2019)

  • v9.0.0(Mar 6, 2019)

  • 3.1.10(Nov 24, 2016)

  • 3.1.9(Nov 24, 2016)

  • 3.1.8(Nov 22, 2016)

  • 3.1.7(Oct 20, 2016)

  • 3.1.6(Oct 19, 2016)

  • 3.1.2(Oct 15, 2016)

  • 3.1.1(Oct 13, 2016)

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

null 9 Dec 14, 2022
Laravel Authentication Log is a package Log user authentication details and send new device notifications.

Laravel Authentication Log is a package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, etc. as well as sends out notifications via mail, slack, or sms for new devices and failed logins.

Anthony Rappa 540 Jan 5, 2023
Allow your model to record the creation, update and deletion of user fingerprints in laravel packages

This laravel package will allow your models to record the the created, updated and deleted by User FingerPrints

Managemize 4 Mar 11, 2022
LERN is a Laravel package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

LERN is a Laravel package that will record exceptions into a database and will notify you via Email, Pushover or Slack.

Tyler Arbon 437 Nov 17, 2022
An interface for the administrator to easily change application settings. Uses Laravel Backpack

Backpack\Settings An interface for the administrator to easily change application settings. Uses Laravel Backpack. Works on Laravel 5.2 to Laravel 8.

Backpack for Laravel 207 Dec 6, 2022
User authentication REST API with Laravel (Register, Email verification, Login, Logout, Logged user data, Change password, Reset password)

User Authentication API with Laravel This project is a user authentication REST API application that I developed by using Laravel and MySql. Setup Fir

Yusuf Ziya YILDIRIM 3 Aug 23, 2022
Laravel Logable is a simple way to log http request in your Laravel application.

Laravel Logable is a simple way to log http request in your Laravel application. Requirements php >= 7.4 Laravel version >= 6.0 Installation composer

Sagar 6 Aug 25, 2022
Log activity inside your Laravel app

Log activity inside your Laravel app The spatie/laravel-activitylog package provides easy to use functions to log the activities of the users of your

Spatie 4.6k Jan 7, 2023
This Package helps you in laravel application to log all desired activity for each request from request entry point to generate response at a single snapshot.

Laravel Scenario Logger This Package helps you in laravel application to log all desired activity for each request from request entry point to generat

Mehrdad Mahdian 6 Sep 27, 2021
A simple Laravel event log package for easy model based logging.

Karacraft Logman A simple Model Event Logging Package Usage Installation composer require karacraft/logman Migrate php artisan migrate Publish php a

Karacraft 0 Dec 28, 2021
Log user authentication actions in Laravel.

Laravel Auth Log The laravel-auth-log package will log all the default Laravel authentication events (Login, Attempting, Lockout, etc.) to your databa

Label84 29 Dec 8, 2022
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

Ryan Chandler 9 Sep 17, 2022
Log executed Laravel SQL queries and their line number and more

A lightweight laravel package for logging executed SQL queries, line number and more

Md.Harun-Ur-Rashid 31 Dec 21, 2022
Laravel Email Audit Log

This service provider will monitor all emails that has been sent out of your system. Sent emails will be stored in email_audit_log table

Aleksandar Djokic 9 Sep 27, 2022
Access laravel log through Filament admin panel

Access laravel log through Filament admin panel Features Syntax highlighting Quickly jump between start and end of the file Refresh log contents Clear

Guilherme Saade 20 Nov 22, 2022
Laravel telegram log is a package that can catch your logs all quite simply

Laravel Telegram log Laravel telegram log is a package that can catch your logs all quite simply. Requirments This package is tested with Laravel v8 i

Muath Alsowadi 4 Aug 3, 2022
Laravel Simple Access Log

Laravel Simple Access Log Many systems need to log user access for auditing purposes. This package creates a database table with sensible fields for l

Irfaan Nujjoo 0 Jan 13, 2022
OPcodes's Log Viewer is a perfect companion for your Laravel app

Log Viewer Easy-to-use, fast, and beautiful Features | Installation | Configuration | Authorization | Troubleshooting | Credits OPcodes's Log Viewer i

null 2.2k Jan 3, 2023
Log requests and group together for aggregated statistics of route usage

Log Laravel route usage statistics Log Laravel requests and responses for statistical purposes and optionally aggregate by hours/days/months for minim

Bilfeldt 108 Dec 11, 2022