Record the change log from models in Laravel

Last update: Jun 28, 2022

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.

GitHub

https://github.com/owen-it/laravel-auditing
Comments
  • 1. 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?

    Reviewed by bbredewold at 2016-06-01 14:35
  • 2. 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
    Reviewed by forestia-dev at 2019-09-02 10:32
  • 3. 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 ?
    Reviewed by edukmattos at 2015-10-02 11:45
  • 4. 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

    Reviewed by wallauschek at 2015-09-24 18:49
  • 5. 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;
        }
    
    Reviewed by ctf0 at 2017-11-04 00:09
  • 6. 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.

    Reviewed by ymslavov at 2017-10-10 22:07
  • 7. 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');
    }
    
    Reviewed by ghost at 2017-06-16 09:27
  • 8. 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.
    Reviewed by crashkonijn at 2018-05-09 12:34
  • 9. 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?

    Reviewed by Harti at 2017-11-04 19:42
  • 10. 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

    Reviewed by caranzojason at 2018-10-31 11:48
  • 11. 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

    Reviewed by rafalau at 2017-02-15 20:47
  • 12. Insert function not working ??

    | Q | A | Insert function not working ??| --- | Bug? | yes | New Feature? | no | Framework | Laravel | Framework version | 8.x.y | Package version | 12.x.y | PHP version | 7.4.y

    Actual Behaviour

    When I try to insert a new user in the controller this way it is not audited. $result = User::insert( [ 'first_name' => $firstName, 'last_name' => $lastName, 'email' => $emailAddress, 'mobile' => $phoneNumber, 'location' => $location, 'password' => Hash::make(1234), 'active_status' => $active_status, 'is_admin' => $is_admin, 'user_role'=>$user_role, 'address'=>$address, 'nic'=>$nic, 'created_at' => date("Y-m-d"), ] );

    Expected Behaviour

    Describe the behaviour you're expecting. 'events' => [ 'insert', 'created', 'updated', 'deleted', 'restored', 'detach', 'attach', 'associate', 'dissociate', 'updateOrCreate', ],

    Reviewed by Prabhath1996 at 2022-06-29 05:20
  • 13. need to add tags when I use custom audits

    | Q | A | ----------------- | --- | Bug? | no | New Feature? | yes | Framework | Laravel | Framework version | 9 | Package version | 13 | PHP version | 8.1

    add tags in custom audits

    I want to add tags when I use custom audits

    Reviewed by mohammadghasemi1379 at 2022-06-25 05:34
  • 14. User morph prefix from config on migration

    On migration use setted morph prefix from config, same as other places https://github.com/owen-it/laravel-auditing/blob/2317a5ed72f0c4256b1c274d3e6ef53db5d0598c/src/Auditable.php#L320 https://github.com/owen-it/laravel-auditing/blob/2317a5ed72f0c4256b1c274d3e6ef53db5d0598c/src/Auditable.php#L332-L333

    Reviewed by erikn69 at 2022-06-24 20:51
  • 15. Way to use the package without the use of Auth?

    | Q | A | ----------------- | --- | Bug? | no | New Feature? | yes | Framework | Laravel | Framework version | 9.0.2 | Package version | 13.0.3 | PHP version | 8.0.8

    Actual Behaviour

    I do not use Auth for users in my service. I see that the implementation of the UserResolver is this:

    image

    Is there any way to do something like:

    $morphPrefix . '_id'   => $user ? $user->id : null,
    $morphPrefix . '_type' => $user ? $user->type: null,
    

    instead of

    $morphPrefix . '_id'   => $user ? $user->getAuthIdentifier() : null,
    $morphPrefix . '_type' => $user ? $user->getMorphClass() : null,
    

    Expected Behaviour

    Because I just want to use the model that I return in my resolver:

    <?php
    namespace App\Resolvers;
    
    use Illuminate\Support\Facades\Request;
    use App\DataServiceModels\User;
    
    class UserResolver implements \OwenIt\Auditing\Contracts\UserResolver
    {
        /**
         * {@inheritdoc}
         */
        public static function resolve()
        {
            $current_user = User::where(['user_id' => Request::get('user_id'), 'type' => Request::get('user_type')])->get();
            $current_user = count($current_user) > 0 ? $current_user[0] : null;
    
            return $current_user;
        }
    }
    

    Possible Solutions

    Make that part configurable? Or is there any way that I can achieve what I am looking for?

    Thanks!

    Reviewed by AlexLightning at 2022-06-07 14:08
  • 16. Need to log updated record's primary key with changed data

    | Q | A | ----------------- | --- | Bug? | no | New Feature? | no | Framework | Laravel | Framework version | 9.x.y | Package version | 13.x.y | PHP version | 8.x.y

    Hi, this is not a bug, I am facing this problem when doing the update, I want to log the updated values with the table id (primary key). How can I achieve that? I am new to this package, please help.

    ex:- when I update a record it will log the updated values. That's totally fine. But I need to log the updated record's primary key too

    Current Behaviour

    Old Values {"balance":"0.00"} new Vaue {"balance":1000}

    Expected Behaviour

    Old Values {"id":2,"balance":"0.00"} new Vaue {"id":2,"balance":1000}

    please help.!!!

    Reviewed by prabathchanakadpl at 2022-04-28 13:16
  • 17. Bug: Cannot read properties of undefined (reading 'fields')

    | Q | A | ----------------- | --- | Bug? |yes | New Feature? | no|yes | Framework | Laravel|Lumen | Framework version | 8.83.9 | Package version | 13.0.3 (reproductible on 12.* as well) | PHP version | 8.0.0

    Actual Behaviour

    When loading resource details page I see this error in console.

    vendor.js?id=54f68b087229ece0c8bb:1 TypeError: Cannot read properties of undefined (reading 'fields')
        at a.mounted (auditable-log:1:2429)
        at It (vendor.js?id=54f68b087229ece0c8bb:1:1151576)
        at nn (vendor.js?id=54f68b087229ece0c8bb:1:1165517)
        at Object.insert (vendor.js?id=54f68b087229ece0c8bb:1:1160612)
        at x (vendor.js?id=54f68b087229ece0c8bb:1:1200548)
        at a.__patch__ (vendor.js?id=54f68b087229ece0c8bb:1:1201906)
        at a.t._update (vendor.js?id=54f68b087229ece0c8bb:1:1173937)
        at a.mn.before (vendor.js?id=54f68b087229ece0c8bb:1:1208526)
        at mn.get (vendor.js?id=54f68b087229ece0c8bb:1:1166941)
        at mn.run (vendor.js?id=54f68b087229ece0c8bb:1:1167825)
    

    Expected Behaviour

    No error at all.

    Steps to Reproduce

    • Install nova and the package.
    • Create a resource
    • Activate the package on that resource.
    • Go to resource Details page.

    Possible Solutions

    Not sure, looks like a javascript error.

    Reviewed by mariusghitoiu at 2022-04-26 11:40
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

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

Apr 20, 2022
Laravel Authentication Log is a package Log user authentication details and send new device notifications.
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.

Jun 23, 2022
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

Mar 11, 2022
An interface for the administrator to easily change application settings. Uses Laravel Backpack
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.

Jun 14, 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.

Jun 29, 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.

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

Feb 5, 2022
Log activity inside your Laravel app
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

Jun 23, 2022
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

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

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

Apr 18, 2022
This package provides a Logs page that allows you to view your Laravel log files in a simple UI
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

May 19, 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

Jun 2, 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

Apr 13, 2022
Access laravel log through Filament admin panel
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

Jun 17, 2022
Log requests and group together for aggregated statistics of route usage
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

Jun 18, 2022
Postgis extensions for laravel. Aims to make it easy to work with geometries from laravel models.

Laravel Wrapper for PostgreSQL's Geo-Extension Postgis Features Work with geometry classes instead of arrays. $model->myPoint = new Point(1,2); //lat

Jul 1, 2022
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.

Laravel-Mediable Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel. Features Filesystem-driven appro

Jun 20, 2022
An Eloquent Way To Filter Laravel Models And Their Relationships

Eloquent Filter An Eloquent way to filter Eloquent Models and their relationships Introduction Lets say we want to return a list of users filtered by

Jun 26, 2022
Easy creation of slugs for your Eloquent models in Laravel

Eloquent-Sluggable Easy creation of slugs for your Eloquent models in Laravel. NOTE: These instructions are for the latest version of Laravel. If you

Jun 25, 2022