LaravelPackages.net
Acme Inc.
Toggle sidebar
alzpk/laravel-change-log

Package that makes it easy to log any changes for your models.

4
0
v0.1.0
About alzpk/laravel-change-log

alzpk/laravel-change-log is a Laravel package for package that makes it easy to log any changes for your models.. It currently has 0 GitHub stars and 4 downloads on Packagist (latest version v0.1.0). Install it with composer require alzpk/laravel-change-log. Discover more Laravel packages by alzpk or browse all Laravel packages to compare alternatives.

Last updated

Laravel Change Log

Package that makes it easy to log any changes for your models. The package uses Laravel's Model Events to log the changes. It will log the changes to the changes relation of the model, when ever a model is created, updated, or deleted.

The package will allow you to revert the latest changes, or revert changes by id, depending on the action.

Setup

  1. Start of by installing the package:
composer require alzpk/laravel-change-log
  1. Publish the package service provider
php artisan vendor:publish --provider="Alzpk\LaravelChangeLog\ChangeLogServiceProvider"
  1. Run the migrations
php artisan migrate

Usage

To use the package, add the trait to the models you want to log:

use Alzpk\LaravelChangeLog\Models\Traits\HasChangeLog;

Examples

Here are some examples of how to use the package.

Use the package

Bellow is an example of how to use the package inside your model.

namespace App\Models;

use Alzpk\LaravelChangeLog\Models\Traits\HasChangeLog;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasChangeLog;
}

Show changes for a model

Bellow is an example of how to use the show changes method.

$product = Product::first();

$product->changes->each(function ($change) {
    dump($change);
});

Revert latest changes

Bellow is an example of how to use the revert latest changes method.

$product = Product::first();

$product->revertLatestChanges();

Revert changes by id

Bellow is an example of how to use the revert changes by id method.

$product = Product::first();

$change = $product->changes->first();

$product->revertChangesById($change->id);
Comments