Package Data | |
---|---|
Maintainer Username: | joshbrw |
Maintainer Contact: | josh@joshbrown.me (Josh Brown) |
Package Create Date: | 2017-07-03 |
Package Last Update: | 2017-08-30 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 15:05:15 |
Package Statistics | |
---|---|
Total Downloads: | 3,405 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A simple, easy-to-use audit logging system with translation at the heart. Uses UUIDs for easy dataset merging and management.
Joshbrw\AuditLogging\AuditLoggingServiceProviders,
under the providers
key in config/app.php
.'Audit' => Joshbrw\AuditLogging\Facades\Audit::class,
under the aliases
key in config/app.php
to register the Facadephp artisan vendor:publish --provider="Joshbrw\\AuditLogging\\AuditLoggingServiceProvider"
- this will publish the migration(s) to your top-level database/migrations
directory.php artisan migrate
to run the migration(s) provided with this package.Joshbrw\AuditLogging\Traits\Eloquent\Auditable
trait.Every Audit Log item has two required attributes:
auditable_type
| auditable_id
- The entity the audit relates tomessage_key
- The translation key of the messageThe option attributes are:
message_replacements
- An array of replacements that should be passed to the translator when displaying the audit log.data
- Any array/object of data that you'd like to store against the Audit Log.user_id
- The ID of the User performing the action being logged. Supports Laravel's Auth and Sentinel by default, allows for custom adapters via the UserResolver
This library ships with an audit()
method, with the following syntax:
/**
* Helper method for logging an audit entry.
* @param mixed $entity The entity to create the log for
* @param string $messageKey The key of the translatable message to use
* @param array|null $messageReplacements Array of replacements for the message
* @param array|null $data Any data to attribute to the audit log item
* @return AuditLog Audit log instance
*/
function audit($entity, string $messageKey, array $messageReplacements = null, array $data = null): AuditLog {
Which simply proxies through to the Joshbrw\AuditLogging\AuditLogManager
service's log()
method, which accepts the same parameters.
The package also ships with a Facade which can be used as \Audit::
and proxies through to the AuditLogManager
, such as Audit::log()
and Audit::translate()
.
You can use the AuditLogRepository
to fetch Audit Logs for a specific Eloquent Model:
Auditable
trait.$user = App\User::first();
$auditLogs = app(Joshbrw\AuditLogging\Repositories\AuditLogRepository::class)->getAllAuditLogs($user);