eyepax/activity_log

There is no license information available for the latest version (dev-master) of this package.

This library can be used to log the activities or requests to track later.

dev-master 2017-08-17 09:45 UTC

This package is auto-updated.

Last update: 2024-05-07 17:47:54 UTC


README

ActivityLog - An activity tracker for Laravel

This library can be used to log the activities or requests to track later.

Eyepax IT Consulting (Pvt) Ltd

Quick start

Install with composer.

composer require "eyepax/activity_log:dev-master"

php artisan vendor:publish

php artisan migrate

Now, a table should have been created named "trn_activity_log". This is where all the activities are logged. Also, a config file named "activity_log.php" will also be created inside config/ folder. You can add activities as key value pair, to identify the activity by ID later. Because, in the table, we store only the activity ID.

Then, add the ActivityLogServiceProvider class in the providers section in config/app.php file.

Eyepax\ActivityLogServiceProvider::class

Then, add the ActivityLog Facade in the aliases section in config/app.php file.

'ActivityLog' => Eyepax\Facades\ActivityLog::class

Using the ActivityLog

This is designed to use with ease, with configurable fields. The below table explains on the fields.

# Field Description Required/Optional Default value
1 performed_user_id If there are any type of user who performed, then that specific type user ID (Ex: Member/Company) Optional 0
2 performed_user_type If there are any type of user who performed, then type ID (Ex: Member/Company) Required
3 performed_user_account_id Users table ID, who performed the action Required
4 action_user_account_id Users table ID, who receives the action Optional 0
5 action_user_id If there are any type of user who receives the effect from action, then that specific type user ID (Ex: Member/Company) Optional 0
6 action_user_type If there are any type of user who receives the effect from action, then type ID (Ex: Member/Company) Optional 0
7 action_id Activity ID (Can check activity_log.php config file) Required
8 platform_type If the application has different sections, then the specific platform type (Ex: Portal A, Portal B) Optional null
9 action_data JSON encoded array of input data Required
10 action_admin_user_id If admin performs the activity, then admin user's ID Optional null
11 api_type Whether it is admin or front end (1 - Admin, 2 - Front end) Optional 1

Add this in the top of the file, where you use ActivityLog.

use Eyepax\ActivityLog;

Then, just add the below code, where you want to log the activity. You can add the relevant fields from the above table.

  • To add a single log entry,
ActivityLog::log(['action_data' => [
    'data' => Input::all()
]]);
  • To add multiple log entries,
ActivityLog::logMultiples([
    ['action_data' => ['data' => Input::all()]], 
    ['action_data' => ['data' => Input::all()]]
]);
  • To get list of logs,
ActivityLog::getLogs($params, $page, $itemsPerPage);
$params - Array of filters. Field keys in the above table (except action_data) can be set here. Additionally, These keys can be set.
    1. "after": Datetime filed, which will give logs after the given time.
    2. "before": Datetime filed, which will give logs before the given time.

$page - Starts from 1. (Default: 1)

$itemsPerPage - Default is 20.
  • To get details of a log entry,
ActivityLog::getLogDetails($logId);