GithubHelp home page GithubHelp logo

owen-it / laravel-auditing Goto Github PK

View Code? Open in Web Editor NEW
2.9K 56.0 384.0 985 KB

Record the change log from models in Laravel

Home Page: https://laravel-auditing.com

License: MIT License

PHP 100.00%
laravel auditing audit lumen eloquent revision logging record tracking observer

laravel-auditing's Introduction

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

For more information on how to use the package, please refer to our official documentation available on laravel-auditing.com or in the repository documentation file. Our documentation provides detailed instructions on how to install and use the package, as well as examples and best practices for auditing in Laravel applications.

Thank you for choosing OwenIt\LaravelAuditing!

Version Information

Version Illuminate Status PHP Version
13.x 7.x.x - 11.x.x Active support 🚀 > = 7.3 | 8.0
12.x 6.x.x - 9.x.x Active support > = 7.3 | 8.0
11.x 5.8.x - 8.x.x End of life > = 7.3
10.x 5.8.x - 7.x.x End of life > = 7.2.5
9.x 5.8.x - 6.x.x End of life > = 7.1.3
8.x 5.2.x - 5.7.x End of life > = 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

Special thanks for keeping this project active.

License

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

laravel-auditing's People

Contributors

achillesp avatar aglipanci avatar ajenbo avatar albvadi avatar andreshg112 avatar anteriovieira avatar arkitecht avatar bskl avatar camih avatar divdax avatar erikn69 avatar felabrecque avatar henriquebremenkanp avatar henriquebremenkanp-rakuten avatar laravel-shift avatar lavieri avatar mammutalex avatar marcoocram avatar marktinsley avatar mitchdesign avatar mortendhansen avatar quetzyg avatar raphaelfranca avatar ricuss avatar s4muel avatar specialtactics avatar stylecibot avatar tiagojpdias avatar tianxingxia-cn avatar zoispag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-auditing's Issues

I need save audit logs in another BD

How configure laravel-auditing for save log in another BD.

Example:
My Model is save data in a connection: mysql.

I have save log in another connection (mysql2).

Is possible?

Laravel Auditing not trigger if i use ->update()

Hei,
i report you about my problem, laravel Auditing not triggered if i use:
Model::find(1)->update($array);

REAL CODE from me is something like this:
$variant->update($variantParams['general']); $variant->touch();

and Auditing will work if i change code like this:
foreach ($variantParams['general'] as $key => $value) { $variant->$key = $value; } $variant->save();

Correct me if i wrong..
Thanks..

Update migration.

I think the migration for the audit log table should be updated to use the configuration table name. Something likeSchema::create(config('auditing.table'), function() {...}); and Schema::drop(config('auditing.table'));'.

Broken migration with 5.1

Migration to create column ipAdress uses method Blueprint::ipAddress(). But this method only available for laravel 5.2.*

Not logging when where is used

Is there any reason why it does not work when I use where and it works when I use find?

[Does Not work]
Police::where('id', $request->poilice_id)->update($flds);

[Works]
Police::find($request->poilice_id)->update($flds);

Closed for extension

The audit function in trait prepares the array to be saved, and also saves it. This breaks SRP and makes it quite impossible to extend. The preparation should be in a different function so that other info can be saved by extending the functions.

I need to add some more info to the log table so I created migration to add the new columns to database. I could only save the newly created fields just by completely overriding the audit function. This is not good as any other additions or changes to audit (like route and ip on new version) would need to be implemented on the extending one also.

Also, by having the call to Log::insert in the same function with the preparation of data, prevents me from being able to use a class that extends Log (and has more fields, maybe mutators) instead of the Log class.

Issue using $dontKeep (Laravel 5.1)

[Symfony\Component\Debug\Exception\FatalErrorException]
App\Organisation and OwenIt\Auditing\AuditingTrait define the same property ($dontKeep) in the composition of App\Organisation. However, the definition differs and is considered incompatible. Class was composed

How to replicate this error:

I set up the models as per the instructions, using $dontKeep to exclude the timestamps, e.g

protected $dontKeep = ['created_at', 'updated_at'];

php artisan db:seed (for another purpose), which invoked the above error message, full stack trace below..

PHP Fatal error:  App\User and OwenIt\Auditing\AuditingTrait define the same property ($dontKeep) in the composition of App\User. However, the definition differs and is considered incompatible. Class was composed in /home/vagrant/Code/uapi/source/app/User.php on line 129
PHP Stack trace:
PHP   1. {main}() /home/vagrant/Code/uapi/source/artisan:0
PHP   2. Illuminate\Foundation\Console\Kernel->handle() /home/vagrant/Code/uapi/source/artisan:36
PHP   3. Symfony\Component\Console\Application->run() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107
PHP   4. Symfony\Component\Console\Application->doRun() /home/vagrant/Code/uapi/source/vendor/symfony/console/Application.php:120
PHP   5. Symfony\Component\Console\Application->doRunCommand() /home/vagrant/Code/uapi/source/vendor/symfony/console/Application.php:189
PHP   6. Illuminate\Console\Command->run() /home/vagrant/Code/uapi/source/vendor/symfony/console/Application.php:838
PHP   7. Symfony\Component\Console\Command\Command->run() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Console/Command.php:136
PHP   8. Illuminate\Console\Command->execute() /home/vagrant/Code/uapi/source/vendor/symfony/console/Command/Command.php:256
PHP   9. Illuminate\Container\Container->call() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Console/Command.php:150
PHP  10. call_user_func_array:{/home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Container/Container.php:503}() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Container/Container.php:503
PHP  11. Illuminate\Database\Console\Seeds\SeedCommand->fire() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Container/Container.php:503
PHP  12. DatabaseSeeder->run() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php:61
PHP  13. Illuminate\Database\Seeder->call() /home/vagrant/Code/uapi/source/database/seeds/DatabaseSeeder.php:52
PHP  14. UserTableSeeder->run() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Seeder.php:42
PHP  15. Illuminate\Database\Eloquent\FactoryBuilder->create() /home/vagrant/Code/uapi/source/database/seeds/UserTableSeeder.php:16
PHP  16. Illuminate\Database\Eloquent\FactoryBuilder->make() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:83
PHP  17. Illuminate\Database\Eloquent\FactoryBuilder->makeInstance() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:105
PHP  18. Illuminate\Database\Eloquent\Model::unguarded() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/FactoryBuilder.php:133
PHP  19. Illuminate\Database\Eloquent\FactoryBuilder->Illuminate\Database\Eloquent\{closure}() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2308
PHP  20. spl_autoload_call() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:132
PHP  21. Composer\Autoload\ClassLoader->loadClass() /home/vagrant/Code/uapi/source/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:132
PHP  22. Composer\Autoload\includeFile() /home/vagrant/Code/uapi/source/vendor/composer/ClassLoader.php:301
PHP  23. include() /home/vagrant/Code/uapi/source/vendor/composer/ClassLoader.php:412

The logging itself works fine, and excludes the timestamps as expected.

Show only changed fields

how can you display only fields that have changed in blade template?

if you define fields in $logCustomFields and using your blade template, custom messages for fields that were not updated still show :(

thanks

edit example:

public static $logCustomFields = [
        'desc'  => 'The desc was defined as {new.desc}',
        'enable_hostdiscovery'  => 'enable_hostdiscovery set to  {new.enable_hostdiscovery}',
        'enable_hostcheck'  => 'enable_hostcheck set to  {new.enable_hostcheck}',
    ];

old_value: {"desc":"testing"}
new_value: {"desc":"testing 2"}

output in blade

The desc was defined as testing 2
enable_hostdiscovery set to
enable_hostcheck set to

Laravel 5.2 config('auth.model') is gone

I noticed this after upgrading. OwenIt\Auditing\Log model has a relation that expects this to exist.

Here's the change for 5.2:
laravel/laravel@8414d45#diff-3fc9d8e570780c4eb337c6f860b1e8e0L22

It looks like it moved here: https://github.com/laravel/laravel/blob/develop/config/auth.php#L70

Here's the relationship in the Log model:
https://github.com/owen-it/laravel-auditing/blob/master/src/Log.php#L52

I'm not sure the proper way to get at this now, just thought I'd bring it up.

Log - messages > Parte II

@anteriovieira
Para ir pensando numa atualizacao (seria bem legal pois nao encontrei nada ainda):

Nas mensagens de logs, para os campos com relacoes em outras tabelas, deveria mostrar a informacao do relacionada ao campo correspondente.

Exemplo:
Alterei a categoria de um produto (de TV para Celular).
Na tebela logs, efetuará o registro do log da category_id de 1 para 2 mas na mensagem do log deveria mostrar de "TV" para "Celular" (textos) e nao os valores do campo.

Nao sei se de repente associar tambem:
protected $doKeepLogOf = ['description', 'category_id']; // Informe os campos que deseja registrar no log.
protected $do???????? = ['description ???', 'categories.id']; // Informe os campos que deseja relacionar no log.

Nao sei se me entendeste ?

PDOException: SQLSTATE[HY000]: General error: 1 no such column: route

Hi

I'm trying to use the package in a blank Laravel project.
It fails in the unit tests with the following error:

1) ExampleTest::testBasicExample
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such column: route (SQL: CREATE TEMPORARY TABLE __temp__logs AS SELECT id, user_id, owner_type, owner_id, old_value, new_value, type, created_at, updated_at, route FROM logs)

I'm using:

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "owen-it/laravel-auditing": "^2.3",
        "doctrine/dbal": "^2.5"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    },

The database used in the unit tests is an in-memory sqlite table.
The issue can be worked around by removing the following lines:

        Schema::table('logs', function (Blueprint $table) {
            $table->dropColumn('route');
            $table->dropColumn('ip');
        });

Can't refresh migration

Hi, I have installed the package and published the migrations and configuration file but if I run:

artisan migrate:refresh --seed

I get:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'AddFieldsToLogTable' not found

SQLSTATE[42703]: Undefined column: 7 ERROR: column "route" of relation "logs" does not exist

Its happenig this error after insert an especific object on my db:

QueryException in Connection.php line 713:
SQLSTATE[42703]: Undefined column: 7 ERROR: column "route" of relation "logs" does not exist
LINE 1: ...ue", "owner_type", "owner_id", "user_id", "type", "route", "...
^ (SQL: insert into "logs" ("old_value", "new_value", "owner_type", "owner_id", "user_id", "type", "route", "ip", "created_at", "updated_at") values (null, {"eventos_id":"2","nome":"nome","descricao":"desc"}, App\Model\Patrocinador, 12, 1, created, sponsors.store, 127.0.0.1, 2016-05-31 23:16:23, 2016-05-31 23:16:23))

my composer

"require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "laravelcollective/html": "5.2.*",
        "owen-it/laravel-auditing": "^2.2"
    },

my model:

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\AuditingTrait;

class Patrocinador extends Model
{
    use AuditingTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'patrocinadores';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['descricao', 'eventos_id', 'logo', 'nome'];

    /**
    * Get the evento that owns the Patrocinador.
    */
    public function evento()
    {
        return $this->belongsTo('App\Model\Evento');
    }
}

where i store my object ( my controller)

public function store(Request $request)
    {
        $sponsor = Patrocinador::create($request->all());

        session()->flash('message', 'ok');      

        return response()->json('true');    
    }

obs:
-i haven't modified anything especial on this model .
-the object i'm trying to store was saved, only the log wasn't

the entire error page .hmtl is here to download

Option to queue auditing

I think it would be cool if the auditing package could queue the queries in the background so the user would not notice any longer loading times whenever another query is executed. Not that it is currently slowing down my application, but I can see when you get alot of data it might affect the application.

BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::user()

Hi there,

Using the package causing the following error in unit tests:

1) ExampleTest::testBasicExample
BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::user()

/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2343
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:1422
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:3506
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:692
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Relation.php:184
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:693
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:664
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:644
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:322
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php:181
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php:142
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:675
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:644
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:322
/Users/balazssebesteny/Sites/laravel-auditing-test/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:646
/Users/balazssebesteny/Sites/laravel-auditing-test/tests/ExampleTest.php:30

See my config in #55

The test I'm using:

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

use App\User;
use App\Test;

use OwenIt\Auditing\Log;

class ExampleTest extends TestCase
{

    use DatabaseMigrations;

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testBasicExample()
    {

        $user = factory(User::class)->create();
        $this->actingAs($user);
        $test = factory(Test::class)->create();
        dump(Log::all()->toArray());
        $this->assertTrue(true);
    }
}


The issue can be worked around by removing the eager loading of the user and owner properties from the the Log class.

Thanks.

Precende Rule on AuditingTrait

Hi, i'm having this problem when trying to use the package in 5.1.

Project\Core\Admin\User and OwenIt\Auditing\AuditingTrait define the same property ($dontKeep) in the composition of Project\Core\Admin\User. However, the definition differs and is considered incompatible. Class was composed

3rd party authentication package support

Right now, this package assumes that the user is using the built-in Laravel Authentication package. This should not be assumed; the configuration should allow for the developers to use other authentication plugins (such as Sentinel)

Logs collection does not update upon deleting an object

While working on some code where I'm using this package, I found that if I delete an object the log collection does not update to contain a log entry for the deletion. This may be expected, but I wanted to be sure. I have soft deletes on my object, so maybe that has something to do with it. Though I do know it's logging the deleting in the logs table.

$obj = new Obj();
$obj->title = 'title';
$result = $obj->save();
$this->assertEquals(1, $result, 'Expecting id of 1 after first record created');

$log = $obj->logs()->first();
$this->assertNotEmpty($log, 'Expected a log entry for the creation of the obj');

$obj->title = 'Updated title';
$obj->save();

$logs = $obj->logs;
$this->assertCount(2, $logs, 'Expected two log entries after changing the title of the obj');

obj->delete();
$logs = $obj->logs;

echo count($logs); // = 2

Also I found that I get an error when trying to use logs()->last().

BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::last()

Selects

Is It possible to audit select?

Tradução para o campo "type"

Olá,

Tem alguma configuração pra traduzir o campo "type" [updated, created, deleted] sem ter que fazer isso manualmente, ou seja, sem ter que criar um mutator?

Obrigado!

Recording IP and Route

Hi, would be awesome if there's a way to record the IP address of the currently connected user in the log.

Also, a record of the route would be welcome too!

Any thought in how to get this?

Thx.

Option dontKeepLogOf being ignored?

Hello,

I implemented this package in a project of mine. Very nice, easy to setup and worked right away. Good stuff!

I noticed that it was logging the password field when I was creating a user, so I added that field to the dontKeepLogOf config option. I still see that field showing up in the logs. I tried this option on other models and the same behavior is there, it still writes to the log any field I ask it to ignore. Here is my User model for reference, what might I be missing?

namespace app;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;
use Silber\Bouncer\Database\HasRolesAndAbilities;
use OwenIt\Auditing\AuditingTrait;

class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract,
                                    SluggableInterface
{
    use Authenticatable, Authorizable, CanResetPassword, SluggableTrait, HasRolesAndAbilities, AuditingTrait;

    /**
     * Fields we DON'T want to register with auditing.
     */
    protected $dontKeepLogOf = ['password', 'remember_token'];

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

Do you have any suggestions as to what I might be doing incorrectly? I am running Laravel Framework version 5.1.26 (LTS) and in my composer.json, I've required "owen-it/laravel-auditing": "^2.1".

Thanks!

Historylog workflow

Hello,

How does the $historyLimit actually work, lets say I have a model with 500 logs and $historyLimit = 500, what happens after any action has been taken, it just stops logging? I think it would be nice if it deletes the oldest row in the logs table.

Auditing in multi-tenancy apps

Hi,

this package is awesome for regular applications and works as expected, but I have the following situation:

  1. I have main DB connection that stores users, roles, permissions and, of course, logs.
  2. The system creates separate DB for each new user, and when a given user is logged in, the application handles a second DB connection, corresponding to the auth user's table.
  3. When I run DB seeders for predefined data in the tables (second connection) the system requires 'logs' table to be present in the user's database.
  4. When logged user creates/updates a given record, the logging is done in the 'logs' table of the main DB connection.

So my question is, is it possible to avoid the need to define the 'logs' table in the second connection (user's database)?

I will provide more details if I wasn't so clear.

Thanks in advance

Tradução para pt_BR

Parabéns pelo pacote ! Muito bom !

Uma dúvida por mais obvia que possa parecer pois estou comecando a utilizar o laravel:

  1. Gostaria traduzir os textos updated in por alterado em. Como faço ?

Formato do output

Boa tarde

Seria legal poder buscar as informações em formato de tabela, e não lista. O motivo seria fazer uma tabela páginada com filtro de pesquisa, pois em sistemas onde temos muitas alterações, uma lista fica complicado de fazer o render do HTML.

User Action Old Value New Value Date #
Anonymous update Value Old New Value 2015-11-17 16:00:00

Fiz aqui no sistema usando desta forma:

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        $logs = Log::with(['user'])->orderBy('created_at', 'desc')->paginate(10);
        $records = User::paginate(15);

        return view('system::users.index', compact('records', 'logs'));
    }

e criando uma view no common

<table class="table table-condensed table-striped">
    <thead>
        <tr>
            <th>{{ trans('dictionary.user') }}</th>
            <th>{{ trans('dictionary.action') }}</th>
            <th>{{ trans('dictionary.old-value') }}</th>
            <th>{{ trans('dictionary.new-value') }}</th>
            <th>{{ trans('dictionary.date') }}</th>
            <th>#</th>
        </tr>
    </thead>
    <tbody>
        @forelse ($logs as $log)
            @forelse ($log->customFields as $custom)
                <tr>
                    <td>{{ $log->user_id ? $log->user_id : 'Anonymous' }}</td>
                    <td>{{ trans("dictionary.{$log->type}") }}</td>
                    <td>{!! arrayToList($log->old) !!}</td>
                    <td>{!! arrayToList($log->new) !!}</td>
                    <td>{{ $log->created_at }}</td>
                    <td>
                        {!! Form::open(['method' => 'get', 'route' => ['system.users.edit', $log->id]]) !!}
                        {!! Form::button('<i class="fa fa-refresh"></i>', ['type' => 'submit', 'class' => 'btn btn-default btn-xs']) !!}
                        {!! Form::close() !!}
                    </td>
                </tr>
            @empty
                <tr>
                    <td colspan="5">{{ trans('dictionary.no-details') }}</td>
                </tr>
            @endforelse
        @empty
            <tr>
                <td colspan="5">{{ trans('dictionary.no-records') }}</td>
            </tr>
        @endforelse
    </tbody>
</table>

Acho que seria legal ter algo assim por default no package. :)

3rd Table Auditing

Hi there, can someone provide examples of enabling audits on 3rd table changes? I am trying to use the attach() and detach() method on the parent object but these changes to the 3rd table go untracked.

Any help appreciated thanks

Monolog

Are there any conflicts with monolog?

I tried using:
$users = \App\User::find(1);
$users->logs;

and returned
`Call to undefined method Illuminate\Support\Facades\Log::newQuery()'

I commented the line 'Log' in the file config/app.php and returned
Class 'Log' not found

Should I create a facade?

Laravel-Auditing with Sentinel

We are trying to use laravel-auditng and so far everything seems to be working great except we're not getting any user information populated. We use the Caralyst/Sentinel package for security so our User object extends \Cartalyst\Sentinel\Users\EloquentUser. Any suggestions on what to check?

Error from the laravel.log file:
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Access level to OwenIt\Auditing\AuditingTrait::getUserId() must be public (as in class Cartalyst\Sentinel\Users\EloquentUser)' in /chsh/app/Objects/User.php:473

Thanks in advance.

audit table name

Is it possible to make the name of the audit table configurable?

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?

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 ?

Adicionar nova coluna

Existe a possibilidade de incluir uma nova coluna no pacote?
Porque tipo preciso relacionar o log a um cliente então eu preciso de uma coluna na tabela tipo, cliente_id para fazer o relacionamento do log, e tipo não sei como fazer isso, porque se fizer no pacote de vocês vou perder minhas alterações quando atualizar o pacote.
Alguma sugestão?

Value of 0 (zero) gets stripped

old_value: {"desc":"test","enable_hostcheck":0}
new_value: {"desc":"testies","enable_hostcheck":"1"}

When using $logCustomFields any value with 0 in the JSON element will get removed from the output display from the blade template.

Laravel-auditing with MongoDB

There is an option in config to use different database connection for the auditing log. Can we use a MongoDB connection?

Audit logs data will surely be rapidly growing data in database, MongoDB is best fit for such insertion oriented function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.