Installation and Setup | laravel-activitylog | Spatie       

 SPATIE  

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

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-activitylog](https://spatie.be/docs/laravel-activitylog/v5)  Installation and Setup

 Version   v5   v4   v3   v2   v1      

 Other versions for crawler [v5](https://spatie.be/docs/laravel-activitylog/v5) [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) 

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

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

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

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

- [ Logging model events ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/logging-model-events)
- [ Define causer for runtime ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/define-causer-for-runtime)
- [ Using placeholders ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/using-placeholders)
- [ Using multiple logs ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/using-multiple-logs)
- [ Disabling logging ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/disabling-logging)
- [ Customizing actions ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/customizing-actions)
- [ Before logging hook ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/before-logging-hook)
- [ Buffering activities ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/buffering)
- [ Log Options ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/log-options)
- [ Causer Resolver ](https://spatie.be/docs/laravel-activitylog/v5/advanced-usage/causer-resolver)

 Installation and Setup
======================

###  On this page 

1. [ Custom table name or database connection ](#content-custom-table-name-or-database-connection)

The package can be installed via composer:

```
composer require spatie/laravel-activitylog
```

The package will automatically register the service provider.

You can publish the migration with:

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

**Note:** The default migration assumes you are using integers for your model IDs. If you are using UUIDs, or some other format, adjust the format of the `subject_id` and `causer_id` fields in the published migration before continuing.

After the migration has been published, you can create the `activity_log` table by running the migrations:

```
php artisan migrate
```

You can optionally publish the config file with:

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

This is the contents of the published config file:

```
return [

    /*
     * If set to false, no activities will be saved to the database.
     */
    'enabled' => env('ACTIVITYLOG_ENABLED', true),

    /*
     * When the clean command is executed, all recording activities older than
     * the number of days specified here will be deleted.
     */
    'clean_after_days' => 365,

    /*
     * If no log name is passed to the activity() helper
     * we use this default log name.
     */
    'default_log_name' => 'default',

    /*
     * You can specify an auth driver here that gets user models.
     * If this is null we'll use the current Laravel auth driver.
     */
    'default_auth_driver' => null,

    /*
     * If set to true, the subject relationship on activities
     * will include soft deleted models.
     */
    'include_soft_deleted_subjects' => false,

    /*
     * This model will be used to log activity.
     * It should implement the Spatie\Activitylog\Contracts\Activity interface
     * and extend Illuminate\Database\Eloquent\Model.
     */
    'activity_model' => \Spatie\Activitylog\Models\Activity::class,

    /*
     * These attributes will be excluded from logging for all models.
     * Model-specific exclusions via logExcept() are merged with these.
     */
    'default_except_attributes' => [],

    /*
     * These action classes can be overridden to customize how activities
     * are logged and cleaned. Your custom classes must extend the originals.
     */
    'actions' => [
        'log_activity' => \Spatie\Activitylog\Actions\LogActivityAction::class,
        'clean_log' => \Spatie\Activitylog\Actions\CleanActivityLogAction::class,
    ],
];
```

Custom table name or database connection
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If you need to use a custom table name or database connection, create a custom Activity model that extends the default one:

```
use Spatie\Activitylog\Models\Activity as BaseActivity;

class Activity extends BaseActivity
{
    protected $table = 'my_custom_activity_log';

    protected $connection = 'my_custom_connection';
}
```

Then set it in the config:

```
'activity_model' => \App\Models\Activity::class,
```

### Database transactions

Without buffering, activities on the same database connection as their subject are rolled back together.

When using a different connection or [buffering activities](/docs/laravel-activitylog/v5/advanced-usage/buffering), the package waits until the subject's transaction commits. If it rolls back, the activities are discarded. These activities have no ID until they are saved, after commit or the next buffer flush.

Writes to separate databases are not atomic: if saving an activity fails after commit, the subject's changes remain saved.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
