sdas/changelog

Log any change in model

v1.0.9 2023-02-19 05:12 UTC

This package is auto-updated.

Last update: 2025-05-19 10:20:15 UTC


README

This package is responsible for logging create, update and delete event in a table and gives the admin a view of what is happening in this system.

Installation

$ composer require sdas/changelog

After installing the package publish the config file

$ php artisan vendor:publish --tag=changelog-config

Published config file will be found in the config folder of your laravel project. Update the config variables according to your project structure.

Publish and migrate the migrations

$ php artisan vendor:publish --tag=changelog-migrations
$ php artisan migrate

Now, run the command below to refresh all the cache

$ php artisan optimize

Great, installation process is done.

Now use Sdas\Changelog\Http\Traits\Trackable trait in any class that extends Illuminate\Database\Eloquent\Model like this

<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Sdas\Changelog\Http\Traits\Trackable;
class Democlass extends Model
{
    use Trackable;
}

Now this package will start to log changes of the table which is represented by your model where you used the Trackable trait.

To view the logs generated by this package go to your_project_url/changelog

Instructions

  1. Query with DB::table won't work in this package

  2. For update and delete event you have to fetch the model object first and then run update command.

    This won't work

     User::where('id', 10)->update(['name'=>'Test name']);
     User::where('id', 10)->delete();
    

    Do like this

     User::find(10)->update(['name'=>'Test name']);
     User::find(10)->delete();