Giter VIP home page Giter VIP logo

laravel-auditable's Introduction

Laravel Auditable

Latest Version on Packagist Software License

Continuous Integration Static Analysis Total Downloads

Laravel Auditable is a simple Laravel auditing package for your Eloquent Model. This package automatically inserts/updates an audit log on your table on who created and last updated the record.

Laravel Version Compatibility

Laravel Package
5.x-10.x 4.x
11.x 11.x

Install via Composer

composer require yajra/laravel-auditable:^11

Publish config file

If you want to modify the withDefault option on auditable columns, you may publish the config file.

php artisan vendor:publish --tag=auditable

Usage

Update your model's migration and add created_by and updated_by field using the auditable() blueprint macro.

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name', 100);
    $table->auditable();
    $table->timestamps();
});

Then use AuditableTrait on your model.

namespace App;

use Yajra\Auditable\AuditableTrait;

class User extends Model
{
    use AuditableTrait;
}

Soft Deletes

If you wish to use Laravel's soft deletes, use the auditableWithDeletes() method on your migration instead:

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name', 100);
    $table->auditableWithDeletes();
    $table->timestamps();
    $table->softDeletes()
});

Afterwards, you need to use AuditableWithDeletesTrait on your model.

namespace App;

use Yajra\Auditable\AuditableWithDeletesTrait;

class User extends Model
{
    use AuditableWithDeletesTrait, SoftDeletes;
}

Dropping columns

You can drop auditable columns using dropAuditable() method, or dropAuditableWithDeletes() if using soft deletes.

Schema::create('users', function (Blueprint $table) {
    $table->dropAuditable();
});

And you're done! The package will now automatically add a basic audit log for your model to track who inserted and last updated your records.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-auditable's People

Contributors

22nick22 avatar brandpublico avatar darrelenano avatar ejgandelaberon avatar gpibarra avatar ivanfernz avatar jidago avatar laravel-shift avatar redredimano avatar rigibore-charlie avatar schonhoff avatar shairayo avatar yajra 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

laravel-auditable's Issues

Add Laravel 7.0 support

Summary of problem or feature request

Add Laravel 7.0 support

Code snippet of problem

System details

  • Operating System
  • PHP Version
  • Laravel Version
  • Laravel-Auditable Version

Delete fails to update deleted_by column

Summary of problem or feature request

As listed in the subject, whenever using the soft deletes, it fails to update the deleted_by column yet deleted_at is being updated. I don't know if this has always happened or if its a recent occurrence, but checking the tables, it would appear as if it has always been this way.

Code snippet of problem

Migration:

Schema::create('incidents', function (Blueprint $table) {
    $table->increments('id');
    $table->auditableWithDeletes();
    $table->timestamps();
    $table->softDeletes()
});

Model

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Yajra\Auditable\AuditableWithDeletesTrait;

class Incident extends Model
{
    use AuditableWithDeletesTrait, SoftDeletes;
}

IncidentController

Incident::where($request->input('incident_id'))->delete();

System details

  • Operating System - CentoOS in Docker
  • PHP Version - 7.3.2
  • Laravel Version - 7.x
  • Laravel-Auditable Version - Current stable

Updated By should not be updated if there is no user authenticated

Summary of problem or feature request

Setting the updated_by field in a Factory has no effect as the value is overwritten by null on save due to there being no currently authenticated user.

Code snippet of problem

    public function definition()
    {
        return [
            'name' => $this->faker->name,
            'email' => $this->faker->unique()->safeEmail,
            'email_verified_at' => now(),
            'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token' => Str::random(10),
            'created_by' => 3, // Stamped as 3
            'updated_by' => 3, // Stamped as NULL
        ];
    }

System details

  • Operating System - PopOS
  • PHP Version - 7.4.9
  • Laravel Version - 8.21.0
  • Laravel-Auditable Version - 4.3.0

Laravel 5.8

Hi,

Will this still work with Laravel 5.8?

Thanks

MassDestroy do not save log

Laravel 7

Actual Behaviour
Do not save log when a use DataTables MassDestroy, if i remove just only one, log save OK.

Model friends.php

namespace App;

use App\Traits\Auditable;
use Yajra\Auditable\AuditableWithDeletesTrait;`

class ProcedureType extends Model
{
    use SoftDeletes, MultiTenantModelTrait, Auditable, AuditableWithDeletesTrait;

   protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at',
    ];
 protected $fillable = [
        'title',
        'created_at',
        'updated_at',
        'deleted_at',
        'created_by_id',
    ];

Controller app\http\admin\FriendsController.php

public function destroy(Friends $friends)
    {
        abort_if(Gate::denies('friends_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $friends->delete();

        return back();

    }
public function massDestroy(MassDestroyFriendsRequest $request)
    {
        Friends::whereIn('id', request('ids'))->delete();

        return response(null, Response::HTTP_NO_CONTENT);

    }

Steps to Reproduce
composer require yajra/laravel-auditable

composer update

open my friends page

select 2 or more on checkbox and click em Mass Destroy (datatables)

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.