Getting Started

Installation

The Nexus CMS depends on auditing so if you use the CMS you will have auditing by default.

Otherwise install it as you would any other Nexus package:

scripts/composer.sh require alberon/nexus-audits    # com req alberon/nexus-audits

Add the "Audit Logs" link to the sidebar (typically under "Administration"):

<script>
    //...
    import LayoutSidebarLinkAudits from '@alberon/nexus-audits/vue/LayoutSidebarLinkAudits';
    //...

    export default {
        components: {
            //...
            LayoutSidebarLinkAudits,
            //...
        },
    }
</script>

<template>
    ...
    <LayoutSidebarLinkAudits />
    ...
</template>

Models

Add the Auditable trait to any model that you want to support audit logs, or the base class if you prefer.

For auto-linking to work in the GUI, also specify the route name on the model.

<?php

use Alberon\NexusAudits\Traits\Auditable;

class SampleModel extends Model
{
    use Auditable;

    protected $viewRoute = 'examples.show';

    // ...
}   

Then use the following methods to in place of the standard ones:

$model->saveAndAudit();                                                         // Calls save() and audits the changes in the model
$model->syncAndAudit('relationshipMethodName', $relatedIds, 'summary text');    // Calls `->relationshipMethodName()->sync($relatedIds)` and audits the results
$model->deleteAndAudit();                                                       // Calls delete() and audits the action

Note: Auditing does not happen automagically. This it to avoid situations where (for example) a bulk update script causes a lot of unnecessary data to be written to the logs.