2017 © Pedro Peláez
 

library activity-log

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

image

regulus/activity-log

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  • Thursday, August 31, 2017
  • by Regulus
  • Repository
  • 12 Watchers
  • 168 Stars
  • 80,346 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 43 Forks
  • 1 Open issues
  • 17 Versions
  • 7 % Grown

The README.md

ActivityLog

A simple and clean Laravel 5 activity logger for monitoring user activity on a website or web application., (*1)

, (*2)

Installation

Basic installation, service provider registration, and aliasing:, (*3)

To install ActivityLog, make sure "regulus/activity-log" has been added to Laravel 5's composer.json file., (*4)

"require": {
    "regulus/activity-log": "0.6.*"
},

Then run php composer.phar update from the command line. Composer will install the ActivityLog package. Now, all you have to do is register the service provider and set up ActivityLog's alias. In app/config/app.php, add this to the providers array:, (*5)

Regulus\ActivityLog\ActivityLogServiceProvider::class,

And add this to the aliases array:, (*6)

'Activity' => Regulus\ActivityLog\Models\Activity::class,

Publishing migrations and configuration:, (*7)

To publish this package's configuration and migrations, run this from the command line:, (*8)

php artisan vendor:publish

You will now be able to edit the config file in config/log.php if you wish to customize the configuration of ActivityLog., (*9)

Note: Migrations are only published; remember to run them when ready., (*10)

To run migration to create ActivityLog's table, run this from the command line:, (*11)

php artisan migrate

, (*12)

Basic Usage

Logging user activity:, (*13)

    Activity::log([
        'contentId'   => $user->id,
        'contentType' => 'User',
        'action'      => 'Create',
        'description' => 'Created a User',
        'details'     => 'Username: '.$user->username,
        'updated'     => (bool) $id,
    ]);

The above code will log an activity for the currently logged in user. The IP address will automatically be saved as well and the developer flag will be set if the user has a developer session variable set to true. This can be used to differentiate activities between the developer and the website administrator. The updated boolean, if set to true, will replace all instances of "Create" or "Add" with "Update" in the description and details fields., (*14)

, (*15)

Advanced Usage

As of version 0.6.0, ActivityLog has built in the ability to dynamically create descriptions based on language keys in Laravel's language files. If you would like to enable this feature without having to set language_key to true when you use the log() function, change defaults.language_key to true in the config file (it is not present by default so you will have to add it)., (*16)

Logging user activity with language keys:, (*17)

    Activity::log([
        'contentType' => 'Record',
        'description' => [
            'created_items', [ // "activity-log::descriptions.created_items" is ":user created :number :items."
                'number' => 2,
                'items'  => 'SPL|labels.record', // "labels.record" in this example has a string of "Record|Records"
            ],
        ],
        'details' => [
            'record',
            'This is Some Kind of Record',
        ],
        'data' => [
            'category' => 'Content',
        ],
    ]);

    echo $activity->getDescription(); // may output "Unknown User created 2 records."

    echo $activity->getDetails(); // may output "Record: This is Some Kind of Record"

    echo $activity->getData('category'); // will output "Content"

In the example above, the items replacement variable in the description has a number of specified properties before the | character which separates them from the actual language variable. The available properties are as follows:, (*18)

S - Return the "singular" string (in the case of "labels.record", "Record")
P - Return the "plural" string (in the case of "labels.record", "Records")
A - Prepend the string with "a" or "an" (example: "a record" instead of just "record")
L - Convert the string to lowercase

In our example above, you will see both singular ("S") and plural ("P") are being used. When both are used, the description builder looks for a number replacement variable to decide whether the singular or plural form should be used., (*19)

Note: The user replacement variable is automatically set based on the record's user ID., (*20)

, (*21)

Getting Linked Content

Set up the content_types config array like the following example:, (*22)

    'item' => [
        'uri'       => 'view/:id',
        'subdomain' => 'items',
        'model'     => 'App\Models\Item',
    ],

You can use getContentItem() to get the item based on the specified model (assuming, in the case of the above specified example, that your content type is set to "Item"). You can also use getUrl() to get the URL of the content item or getLinkedDescription() to get a linked description for the item., (*23)

, (*24)

Displaying Action Icons

Display an action icon based on config setup:, (*25)

    echo $activity->getIconMarkup();

You can also use getIcon() to get just the icon class from which to build your own icon markup., (*26)

The Versions

31/08 2017

dev-master

9999999-dev

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

18/04 2017

v0.6.8

0.6.8.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

20/02 2017

v0.6.7

0.6.7.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

09/02 2017

v0.6.6

0.6.6.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

05/12 2016

v0.6.5

0.6.5.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

25/09 2016

v0.6.4

0.6.4.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

03/09 2016

v0.6.3

0.6.3.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

14/06 2016

v0.6.2

0.6.2.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

25/05 2016

v0.6.1

0.6.1.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

15/05 2016

v0.6.0

0.6.0.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

03/02 2016

v0.5.5

0.5.5.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

09/12 2015

v0.5.4

0.5.4.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

22/06 2015

v0.5.3

0.5.3.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

19/04 2015

v0.5.2

0.5.2.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

21/03 2015

v0.5.1

0.5.1.0

A clean and simple Laravel 5 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

27/11 2014

v0.3.1

0.3.1.0

A clean and simple Laravel 4 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman

26/07 2014

v0.3.0

0.3.0.0

A clean and simple Laravel 4 activity logger for monitoring user activity on a website or web application.

  Sources   Download

MIT

The Requires

 

by Cody Jassman