Custom Audits
To create a custom audit record, use the AuditManager class (with dependency injection) or the Audit facade:
use Alberon\NexusAudits\Facades\Audit;
// Custom audit with no related model
Audit::create([
'action' => 'Audit action',
'variant' => 'warning',
'renderer' => 'VueComponentForRendering',
'details_json' => ['example' => 'data related to the audit'],
]);
// Custom audit with a related model
Audit
::make([
'action' => 'Audit action',
'variant' => 'warning',
'renderer' => 'VueComponentForRendering',
'details_json' => ['example' => 'data related to the audit'],
])
->setAuditable($model, $model->getAuditableRoute())
->save();
This will create an instance of AuditLog and automatically fill in the user details. The fields are:
action- Text, displayed in the logrenderer- Vue component that displays the details of the audit entrydetails_json- Any additional data required by the renderervariant- Bootstrap variant, used for styling the action label
The default renderers are:
ModelCreatedModelUpdatedModelDeletedRelationshipsUpdatedVerificationEmail
To create custom renderers, add them to resources/nexus-audits/vue/Renderer/ (or assets/nexus-audits/vue/Renderer/ in another package). Take a look at the default renderers to see how they work.