Introduction | laravel-activitylog | Spatie

 SPATIE

  Laravel Activity Log
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-activitylog](https://spatie.be/docs/laravel-activitylog/v4)  Introduction

 Version   v4   v3   v2   v1

 Other versions for crawler [v4](https://spatie.be/docs/laravel-activitylog/v4) [v3](https://spatie.be/docs/laravel-activitylog/v3) [v2](https://spatie.be/docs/laravel-activitylog/v2) [v1](https://spatie.be/docs/laravel-activitylog/v1)

- [ Introduction ](https://spatie.be/docs/laravel-activitylog/v4/introduction)
- [ Support us ](https://spatie.be/docs/laravel-activitylog/v4/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-activitylog/v4/requirements)
- [ Installation and Setup ](https://spatie.be/docs/laravel-activitylog/v4/installation-and-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-activitylog/v4/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-activitylog/v4/changelog)
- [ Upgrading ](https://spatie.be/docs/laravel-activitylog/v4/upgrading)
- [ About us ](https://spatie.be/docs/laravel-activitylog/v4/about-us)

Basic usage
-----------

- [ Logging activity ](https://spatie.be/docs/laravel-activitylog/v4/basic-usage/logging-activity)
- [ Cleaning up the log ](https://spatie.be/docs/laravel-activitylog/v4/basic-usage/cleaning-up-the-log)

Advanced usage
--------------

- [ Logging model events ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events)
- [ Manipulate changes array ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/manipulate-changes-array)
- [ Batch Logs ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/batch-logs)
- [ Define causer for runtime ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/define-causer-for-runtime)
- [ Using placeholders ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/using-placeholders)
- [ Using multiple logs ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/using-multiple-logs)
- [ Disabling logging ](https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/disabling-logging)

API
---

- [ Log Options ](https://spatie.be/docs/laravel-activitylog/v4/api/log-options)
- [ Log Batch ](https://spatie.be/docs/laravel-activitylog/v4/api/log-batch)
- [ Causer Resolver ](https://spatie.be/docs/laravel-activitylog/v4/api/causer-resolver)
- [ Event Bag ](https://spatie.be/docs/laravel-activitylog/v4/api/event-bag)

 Laravel Activity Log
======================

Log activity inside your Laravel app
------------------------------------

 Easy to use functions to log the activities of the users of your app.

 [    Repository ](https://github.com/spatie/laravel-activitylog)

 [    Open Issues ](https://github.com/spatie/laravel-activitylog/issues)

    43,790,863

    5,770

Introduction
------------

###  On this page

1. [ We have badges! ](#content-we-have-badges)

The `spatie/laravel-activitylog` package provides easy to use functions to log the activities of the users of your app. It can also automatically log model events. All activity will be stored in the `activity_log` table.

Here's a litte demo of how you can use it:

```
activity()->log('Look mum, I logged something');
```

You can retrieve all activity using the `Spatie\Activitylog\Models\Activity` model.

```
Activity::all();
```

Here's a more advanced example:

```
activity()
   ->performedOn($anEloquentModel)
   ->causedBy($user)
   ->withProperties(['customProperty' => 'customValue'])
   ->log('Look mum, I logged something');

$lastLoggedActivity = Activity::all()->last();

$lastLoggedActivity->subject; //returns an instance of an eloquent model
$lastLoggedActivity->causer; //returns an instance of your user model
$lastLoggedActivity->getExtraProperty('customProperty'); //returns 'customValue'
$lastLoggedActivity->description; //returns 'Look mum, I logged something'
```

Here's an example on [event logging](/docs/laravel-activitylog/v4/advanced-usage/logging-model-events).

```
$newsItem->name = 'updated name';
$newsItem->save();

//updating the newsItem will cause an activity being logged
$activity = Activity::all()->last();

$activity->description; //returns 'updated'
$activity->subject; //returns the instance of NewsItem that was created
```

Calling `$activity->changes` will return this array:

```
[
   'old' => [
        'name' => 'original name',
        'text' => 'Lorum',
    ],
    'attributes' => [
        'name' => 'updated name',
        'text' => 'Lorum',
    ],
];
```

We have badges!
---------------------------------------------------------------------------------------------------

 [![spatie/laravel-activitylog](https://img.shields.io/badge/packagist-spatie/laravel-activitylog.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-activitylog) [![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-activitylog.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-activitylog) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/spatie/laravel-activitylog/blob/master/LICENSE.md) [![Build Status](https://img.shields.io/travis/spatie/laravel-activitylog/master.svg?style=flat-square)](https://travis-ci.org/spatie/laravel-activitylog) [![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-activitylog.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-activitylog) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-activitylog.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-activitylog)
