PHPackages                             fiopay/activitylog - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. fiopay/activitylog

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

fiopay/activitylog
==================

A very simple activity logger to monitor the users of your website or application

2.4.3(9y ago)09MITPHPPHP &gt;=5.4.0

Since May 6Pushed 7y ago2 watchersCompare

[ Source](https://github.com/fiopay/activitylog)[ Packagist](https://packagist.org/packages/fiopay/activitylog)[ Docs](https://github.com/spatie/activitylog)[ RSS](/packages/fiopay-activitylog/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (20)Used By (0)

Log the activity of your users
==============================

[](#log-the-activity-of-your-users)

[![Latest Version](https://camo.githubusercontent.com/72c3fbb57f31e0b6b58bea6d2433c2a2ecf840e1dedace64fee4991399857319/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7370617469652f61637469766974796c6f672e7376673f7374796c653d666c61742d737175617265)](https://github.com/spatie/activitylog/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/88d6952281dec614f3b6fec18a785ff920c5df911647bf262c0a177ad2755ff9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f61637469766974796c6f672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/activitylog)[![SensioLabsInsight](https://camo.githubusercontent.com/1fcaac7e37637706e32c3c5407870a0042a1eef2335d566ced45490d86013ab9/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f63343838303963372d636462332d346538362d393734622d6164396336323832626333632e737667)](https://insight.sensiolabs.com/projects/c48809c7-cdb3-4e86-974b-ad9c6282bc3c)[![Total Downloads](https://camo.githubusercontent.com/33d0b4ac423346a03360988c4952aeeb8544e6887fc922fc62fb09e88aa009dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f61637469766974796c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/activitylog)

EOL-warning
-----------

[](#eol-warning)

This package has been abandoned on 2016-06-28. Please use [laravel-activitylog](https://github.com/spatie/laravel-activitylog) instead.

Description
-----------

[](#description)

This Laravel 5 package provides a very easy to use solution to log the activities of the users of your Laravel 5 app. All the activities will be logged in a db-table. Optionally the activities can also be logged against the default Laravel Log Handler.

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

### Note:

[](#note)

If you're using Laravel 4, take a look at version 0.3.0 of this package.

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Installation
------------

[](#installation)

This package can be installed through Composer.

```
composer require spatie/activitylog
```

This service provider must be registered.

```
// config/app.php

'providers' => [
    '...',
    'Spatie\Activitylog\ActivitylogServiceProvider',
];
```

You'll also need to publish and run the migration in order to create the db-table.

```
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="migrations"
php artisan migrate

```

Activitylog also comes with a facade, which provides an easy way to call it.

```
// config/app.php

'aliases' => [
	...
	'Activity' => 'Spatie\Activitylog\ActivitylogFacade',
];
```

Optionally you can publish the config file of this package.

```
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"

```

The configuration will be written to `config/activitylog.php`. The options provided are self explanatory.

Usage
-----

[](#usage)

### Manual logging

[](#manual-logging)

Logging some activity is very simple.

```
//at the top of your file you should import the facade.
use Activity;
...
/*
  The log-function takes two parameters:
  	- $text: the activity you wish to log.
  	- $user: optional can be an user id or a user object.
  	         if not proved the id of Auth::user() will be used

*/
Activity::log('Some activity that you wish to log');
```

The string you pass to function gets written in a db-table together with a timestamp, the ip address and the user agent of the user.

### Log model events

[](#log-model-events)

This package can log the events from your models. To do so your model must use the `LogsActivity`-trait and implement `LogsActivityInterface`.

```
use Spatie\Activitylog\LogsActivityInterface;
use Spatie\Activitylog\LogsActivity;

class Article implements LogsActivityInterface {

   use LogsActivity;
...
```

The interface expects you to implement the `getActivityDescriptionForEvent`-function.

Here's an example of a possible implementation.

```
/**
 * Get the message that needs to be logged for the given event name.
 *
 * @param string $eventName
 * @return string
 */
public function getActivityDescriptionForEvent($eventName)
{
    if ($eventName == 'created')
    {
        return 'Article "' . $this->name . '" was created';
    }

    if ($eventName == 'updated')
    {
        return 'Article "' . $this->name . '" was updated';
    }

    if ($eventName == 'deleted')
    {
        return 'Article "' . $this->name . '" was deleted';
    }

    return '';
}
```

The result of this function will be logged, unless the result is an empty string.

### Using a before handler.

[](#using-a-before-handler)

If you want to disable logging under certain conditions, such as for a specific user, create a class in your application namespace that implements the `Spatie\Activitylog\Handlers\BeforeHandlerInterface`.

This interface defines an `shouldLog()` method in which you can code any custom logic to determine whether logging should be ignored or not. You must return `true` the call should be logged.

To en the namespaced class nameto the `beforeHandler` field in the configuration file:

```
'beforeHandler' => '\App\Handlers\BeforeHandler',
```

For example, this callback class could look like this to disable logging a user with id of 1:

```
