Download the PHP package yungts97/laravel-user-activity-log without Composer
On this page you can find all versions of the php package yungts97/laravel-user-activity-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-user-activity-log
Laravel User Activity Log
yungts97/laravel-user-activity-log
is a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app. It provides automatic logging for the model events without complicated action. All activity will be stored in the logs
table.
📦 Environment Requirements
PHP
: ^8.0
Laravel
: ^8.x - ^9.0
🚀 Installation
You can install the package via composer:
The package will automatically register a service provider.
After that, we still need one more step to complete the installation by run this command.
✨ How to use?
This package is very simple and easy to use. The only thing you need to do is add the Loggable
trait in your model class.
It might troublesome if you have a lot of models. You could have a base class for your models and add Loggable
trait in your base model.
If you don't want to log for any child class of the base model, you can add SkipLogging
trait to skip the log for the model.
Sometimes, you don't want to save certain attributes of your model in logging. You can add $log_hidden
attribute to your model.
You can retrieve all activity using the Yungts97\LaravelUserActivityLog\Models\Log
model.
However, you can get activity logs from a model by using this.
You allowed to specify the mode for the edit
event log. There are two modes available now simple
/full
. The default mode is full
.
⚙️ Configuration
You can change the configuration of this package on config/user-activity-log.php
.
🐣 API Routes
Endpoint | Method | Response Format | Description |
---|---|---|---|
/logs |
GET |
JSON | To retrieve user activity logs. |
/logs/filter-options |
GET |
JSON | To retrieve filter options for filtering logs. |
/logs/{log_id} |
GET |
JSON | To retrieve specific activity log. |
Available paramaters for log filtering: | Parameter | Type | Description |
---|---|---|---|
page |
integer |
The page number for log pagination. | |
itemsPerPage |
integer |
The number item per page for log pagination | |
userId |
integer |
Filtering logs by the user ID. | |
dataId |
integer |
Filtering logs by the data ID. | |
logType |
string |
Filtering logs by log type. | |
tableName |
string |
Filtering logs by the table name. | |
dateFrom |
string |
Filtering logs by the date range. (Must have dateFrom & dateTo paramaters) | |
dateTo |
string |
Filtering logs by the date range. (Must have dateFrom & dateTo paramaters) |
Exp. http://example.com/api/logs?page=1&itemsPerPage=10&userId=517
📬 Sample Response
/logs
/logs/filter-options
/logs/77
🎩 Artisan Commands
Command | Description | Option |
---|---|---|
user-activity-log:install | Preparing all the files it needed for the user activity log package. | N/A |
user-activity-log:flush | Remove all the user activity log records that in the database. | N/A |
user-activity-log:clean | Remove the user activity log records that in the database. | --day , --month , --year , --date |
✒️ Options for user-activity-log:clean
Option | Value | Example | Description |
---|---|---|---|
--day |
numeric | --day=7 |
Delete user activity log older than N days. |
--month |
mm/yyyy | --month=01/2022 |
Delete user activity logs for a month of the year. |
--year |
yyyy | --year=2022 |
Delete user activity logs for a year. |
--date |
yyyy | --date=15/02/2022 |
Delete user activity logs for a specific date. |
⚠️ Notice:
Without any option applied by default is --day=7
📃 License
The MIT License (MIT). Please see License File for more information.