jeroen-g/activity-logger

An activity logger for Laravel

Installs: 63

Dependents: 0

Stars: 11

Watchers: 1

Forks: 1

Language: PHP

v2.0 2015-06-11 22:30 UTC

README

A simple activity logger for Laravel 5. For laravel 4, use version 1 of this package.

Scrutinizer Quality Score Latest Stable Version License

Installation

Via Composer

$ composer require jeroen-g/activity-logger

The following command installs the package without the testing requirements.

$ composer require jeroen-g/activity-logger --update-no-dev

Add the service provider in config/app.php:

JeroenG\ActivityLogger\ActivityLoggerServiceProvider::class,

And in the same file, add the alias:

'Activity' =>  JeroenG\ActivityLogger\Facades\ActivityLogger::class,

Then publish the package's migration files.

$ artisan vendor:publish

The last thing to do is to migrate:

$ artisan migrate

Usage

Log an activity

Activity::log($message, $context, $date);

Message is required, the rest is optional. $context is an array which can contain any data you want to save. $date is a timestamp, it defaults to the current timestamp.

Get all logs

Activity::getAllLogs();

Get one log

You only need to pass the id of a log.

Activity::getLog(1);

Get all logs within timespan

$yesterday = Carbon\Carbon::yesterday();
$tomorrow = Carbon\Carbon::tomorrow();

Activity::getLogsBetween($yesterday, $tomorrow);

This function needs two parameters, all logs created between these timestamps are returned.

Get the most recent logs

Activity::getRecentLogs(10);

The default of 5 logs is used when no number is passed.