217

Product support

Get help in the plugin support forum.

Categories

Overview

  • This plugin creates a logbook for changes in an Eloquent model.
  • The plugin also provides a Form Widget and Report Widget to display the log changes.
  • The Form Widget can also show logs of related models, so all changes can be visible.
  • See the documentation how to use the logbook Form Widget and trait.
Icon

Icon made by popcorn-arts from www.flaticon.com

Usage

Model

Use the LogChanges trait in your model. This trait will automatically save changes from the model in the database.

use Jacob\Logbook\Traits\LogChanges;

If you want to ignore fields that don't need the be logged, add this to your model. By default the updated_at field is ignored.

/** @var array $ignoreFields fields to ignore */
protected $ignoreFieldsLogbook = [
    'updated_at',
];

If you want to provide a custom log book model display name you can add this to your model:

/**
 * Here you can override the model name that is displayed in the log files.
 * The name is going to be translated when possible.
 */
public $logBookModelName = 'MyModelName'

If you want to delete the logs when the model is deleted you can add the following code to your model.

/**
 * Delete log book items after model is deleted
 *
 * If true -> log items are deleted when the model is deleted
 * If false -> a new log item will be created with status deleted.
 *
 * @var bool
 */
protected $deleteLogbookAfterDelete = false;

If you want to change the displayed column name, you can add the following code to your model. This can be usefull if you want to give a translation string for the column

/**
 * If you override this function you can change the column name that is displayed in the log book
 * The returned column will be translated if it is possible
 *
 * @param string $column
 * @return string
 */
public static function changeLogBookDisplayColumn($column)
{
    return 'example.plugin::lang.' . $column;
}

You can also override the displayed value. You have to add the following function to your model.

/**
 * If you override this function you can change the value that is displayed in the log book
 * This can be useful for example with a dropdown
 *
 * @param $column
 * @param $value
 * @return string
 */
public static function changeLogBookDisplayValue($column, $value)
{
    if ($column) {
        // do something
    }

    return $value;
}

If you want to hide the undo button for this model specifically, you can add $logBookUndoable to your model. You can also disable the undo button in the log book form widget.

/**
 * Hides or shows undo button for current field
 *
 * @var bool $logBookLogUndoable
 */
public $logBookLogUndoable = false

Form Widget

You can use the formwidget as follows: MAKE SURE to set an underscore in front of the form field name. for example _logbook, because the Form Widget doesn't has a save value.

Options:

Option Default type
limitPerPage 20 int
startPage 1 int
showLogRelations null array or string
showSoftDeletedRelations null array or string
showUndoChangesButton true bool
refreshFormAfterUndo true bool

Example:

_logbook@update:
    type: jacob_logbook_log
    limitPerPage: 10 #optional
    startPage: 1 #optional
    showLogRelations: #optional (contains the name(s) of the relations)
        - customer
        - anotherRelationName
    showSoftDeleteRelations: #optional (contains the name(s) of the relations with soft delete support)
        - relationNameWithSoftDeletes
    showUndoChangesButton: true #optional
    refreshFormAfterUndo: false #optional
  • Found the plugin useful on 22 Nov, 2019

    Very powerful plugin to monitoring any changes in your model! Thanks for it.

  • Found the plugin useful on 3 Oct, 2019

    Excellent addition to any plugin that needs to track changes to the database. Now we know who did what and when. It's like CCTV, but with less wires.

  • Found the plugin useful on 14 Nov, 2018

    Its very helpful as a log for any changes

2.1.0

Add support for jsonable columns

Mar 05, 2022

2.0.2

Fix report widget

Oct 05, 2020

2.0.1

Remove php 7.4 property types

Jun 02, 2020

2.0.0

Add support for soft deleted models, cleanup code and drop support for php 7.0

May 30, 2020

1.0.4

Update indexes for faster query results

Feb 14, 2020

1.0.3

Add undo button to form widget and add report widget.

Nov 02, 2018

1.0.2

Fix error when changing properties from the LogChanges trait.

Nov 01, 2018

1.0.1

First version of Logbook

Oct 30, 2018