Download the PHP package dcodegroup/activity-log without Composer
On this page you can find all versions of the php package dcodegroup/activity-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dcodegroup/activity-log
More information about dcodegroup/activity-log
Files in dcodegroup/activity-log
Package activity-log
Short Description Simple package which dcode uses to manage activity logs
License MIT
Informations about the package activity-log
Laravel Activity Log
The dcodegroup/activity-log
package provides a simple and unified approach to track and record activity / interactions
against your Laravel models (and relations). Capture changes, updates, and user interactions to enhance transparency and
auditing in your application in a centralised and consistent approach.
Update note
Since version 1.1.1
we are no longer need to use observers to listen for changes from the
model. bootActivityLoggable
in ActivityLoggable
trait solved that. Make sure to remove duplicate observers before
updating
Installation
Add the following to your package.json file:
PHP
You can install the package via composer:
Then run the install command.
Run the migrations
User Model
Add the following contract to the User
model.
JS
Add the following alias to vite.config.js
Add the following js to your index.js
file.
In your app.scss
file add the following
Seem to need this in tailwind.config.js
under spacing:
Update the module exports under content:
Update the vue il8n package to load additional paths
Run the npm build (dev/prod)
Configuration
Most of configuration has been set the fair defaults. However you can review the configuration file
at config/activity-log.php
and adjust as needed
Value | Options | Description |
---|---|---|
middleware | Include a specification of what middleware this package should include. | |
layout_path | The dot notation path to the resource/view that you would like to use for the Activity Log. | |
content_section | The variable in the view that will contain the output of the Activtity Log. |
Usage
The package provides an endpoints which you can use. See the full list by running
They are
[example.com/activity-logs] Which is where you will form index. This is by default protected auth middleware but you can modify in the configuration. This is where you want to link to in your admin and possibly a new window
QueryBuilder Filters
Located in
Traits for activity log model
Located in
ActivityLoggable Trait
The ActivityLoggable
trait provides functionality for logging activities and communication logs related to a model.
Methods
logCreate(): void
: Automatically create activity log every time a new model is created. (support from version 1.1.1)logUpdate(): void
: Automatically create activity log every time when model is updated. (support from version 1.1.1)logDelete(): void
: Automatically create activity log every time when model is deleted. (support from version 1.1.1)getActivityLogEmails(): array
: Get the emails associated with activity logs.activities(): Collection
: Get the collection of activities associated with the model.modelRelation(): Collection
: Get the relationship between the model column with the related table.modelRelation
also has the effect of limiting logging to defined columns instead of logging all changes from the model when you declaregetModelChangesJson(true)
Example of define modelRelation via model using ActivityLoggable
when declared like this instead of activity log shows like this. account_id: 1 -> 20
The result will return like
this: Account: Alison Cahill -> Annie Pollock
.
getModelChanges(?array $modelChangesJson = null): string
: Get the model changes as a formatted string.getModelChangesJson(bool $allowCustomAttribute = false): array
: Get the model changes as an array of JSON. If$allowCustomAttribute
=true
If we want to limit the storage of fields defined in modelRelation;false
: If we want to storage all model changecreateActivityLog(array $description): ActivityLog
: Create a new activity log.
Example of define activity log via model using ActivityLoggable
If you have a user case where you want the log messages to be logged against another model, Example. You have an Order
model and you want the OrderItem
models to be recorded against the Order
. Then do as below.
with the OrderItem
model add the method targetModel
Normally a model with have the field name
title
or label
. This package can work this out in most cases. However if you have a none standard field used to name a model you can use the below method to customise the label for the model.
If no label is found then a ModelLabelNotDefinedException
exception will be thrown.
`
You can give any model a custom label by adding the following method to the model. If this is not set then Str::headline will be used on the model.
`
Automatically the package will try and find the key for the model. Typically, this will be a field named name
, title
or label
.
However this may not always be the case and the key may change depending on the the state of a model. Eg type Quote might be quote_number
Order might use sales_order_number
.
If one of the defaults is not found then an ModelKeyNotDefinedException
exception will be thrown.
This should only ever occur in your local environment. If this occurs then implement the follow method in your model.
By default this package will log all fields except for created_at
, updated_at
, deleted_at
, password
, and id
.
If you wish to exclude other fields on your model such as third party api tokens. Then implement the following method in your model.
php use Illuminate\Support\Collection;
... public function activityLogFieldFormatters(): Collection { return collect([ 'price' => fn ($value) => Number::currency(($value / 100), 'AUD'), ]); } bash src\Support\Traits\ReadMailableTrait.php html
## Events
The package provides the following events:
* **`ActivityLogCommentCreated`**: This event is fired when an activity log comment is created. The event receives the
activity log
instance.
* **`ActivityLogCommentDeleted`**: This event is fired when an activity log comment is deleted. The event receives the
activity log instance.
* **`ActivityLogCommentUpdated`**: This event is fired when an activity log comment is update. The event receives the
activity log instance.
* **`ActivityLogCommunicationRead`**: This event is fired when an communication log is marked read. The event receives the
activity log instance.
## Usage
In order to log anything add the following trait to a model you want to log on.
In addition, we can add activity log wherever we want the model
# Changelog
Please see [CHANGELOG](./CHANGELOG.md) for more information about recent changes.
# Contributing
We believe in the power of collaboration! If you share our passion for pushing the boundaries of business software, feel
free to contribute, report issues, or suggest improvements. Your insights make us better.
# Security
If you've found an issue related to this package that includes any security concerns; please
email [[email protected]](mailto:[email protected]) to ensure that we can prioritise the concerns in a
confidential manner.
# Credits
This project is supported & funded by [Dcode Group](https://github.com/dcodegroup) and the team - both past and present.
Special mention to:
- [Dcode Group](https://github.com/dcodegroup)
- [All Contributors](./graphs/contributors)
## About Dcode Group
Dcode Group specializes in crafting tailored software solutions utilizing the Laravel framework. Our focus lies in
developing business, financial, and process-driven systems designed to support unique business operations. Leveraging
packages like this one, we streamline common features/functions across projects, ensuring swift integration of broad
functionalities while enhancing overall code base maintenance and management. Find out more about
# License
All versions of activity-log with dependencies
coduo/php-to-string Version ^3.2
laravel/framework Version ^10.2|^11.0|^12.0
nesbot/carbon Version ^2.72|^3.0
spatie/laravel-query-builder Version ^4.0.4|^5.7|^6.0