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 [
'enabled' => env('ACTIVITYLOG_ENABLED', true),
'clean_after_days' => 365,
'default_log_name' => 'default',
'default_auth_driver' => null,
'include_soft_deleted_subjects' => false,
'activity_model' => \Spatie\Activitylog\Models\Activity::class,
'default_except_attributes' => [],
'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,