From f55d4e70bd0371a869aafd2eeb28f12f1d486a7d Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Fri, 31 Oct 2025 15:07:01 +0700 Subject: [PATCH] feat: install and configure spatie activity log --- composer.json | 1 + composer.lock | 93 ++++++++++++++++++- config/activitylog.php | 52 +++++++++++ ...10_31_144909_create_activity_log_table.php | 27 ++++++ ...add_event_column_to_activity_log_table.php | 22 +++++ ...atch_uuid_column_to_activity_log_table.php | 22 +++++ 6 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 config/activitylog.php create mode 100644 database/migrations/2025_10_31_144909_create_activity_log_table.php create mode 100644 database/migrations/2025_10_31_144910_add_event_column_to_activity_log_table.php create mode 100644 database/migrations/2025_10_31_144911_add_batch_uuid_column_to_activity_log_table.php diff --git a/composer.json b/composer.json index 7c27770..a0e602d 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "livewire/flux-pro": "2.2.5", "livewire/livewire": "^3.6", "rappasoft/laravel-livewire-tables": "^3.7", + "spatie/laravel-activitylog": "^4.10", "spatie/laravel-medialibrary": "^11.15", "spatie/laravel-permission": "^6.21", "spatie/laravel-settings": "^3.4", diff --git a/composer.lock b/composer.lock index c547200..47ff7e5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "65ae2bd836da8b8950b543add245d474", + "content-hash": "5741a5b81c8f68f6d656467cf2e24651", "packages": [ { "name": "archtechx/enums", @@ -5229,6 +5229,97 @@ }, "time": "2024-11-04T08:24:54+00:00" }, + { + "name": "spatie/laravel-activitylog", + "version": "4.10.2", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-activitylog.git", + "reference": "bb879775d487438ed9a99e64f09086b608990c10" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-activitylog/zipball/bb879775d487438ed9a99e64f09086b608990c10", + "reference": "bb879775d487438ed9a99e64f09086b608990c10", + "shasum": "" + }, + "require": { + "illuminate/config": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0", + "illuminate/database": "^8.69 || ^9.27 || ^10.0 || ^11.0 || ^12.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.6.3" + }, + "require-dev": { + "ext-json": "*", + "orchestra/testbench": "^6.23 || ^7.0 || ^8.0 || ^9.0 || ^10.0", + "pestphp/pest": "^1.20 || ^2.0 || ^3.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\Activitylog\\ActivitylogServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Spatie\\Activitylog\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Sebastian De Deyne", + "email": "sebastian@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + }, + { + "name": "Tom Witkowski", + "email": "dev.gummibeer@gmail.com", + "homepage": "https://gummibeer.de", + "role": "Developer" + } + ], + "description": "A very simple activity logger to monitor the users of your website or application", + "homepage": "https://github.com/spatie/activitylog", + "keywords": [ + "activity", + "laravel", + "log", + "spatie", + "user" + ], + "support": { + "issues": "https://github.com/spatie/laravel-activitylog/issues", + "source": "https://github.com/spatie/laravel-activitylog/tree/4.10.2" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2025-06-15T06:59:49+00:00" + }, { "name": "spatie/laravel-medialibrary", "version": "11.15.0", diff --git a/config/activitylog.php b/config/activitylog.php new file mode 100644 index 0000000..64b924a --- /dev/null +++ b/config/activitylog.php @@ -0,0 +1,52 @@ + env('ACTIVITY_LOGGER_ENABLED', true), + + /* + * When the clean-command is executed, all recording activities older than + * the number of days specified here will be deleted. + */ + 'delete_records_older_than_days' => null, + + /* + * 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 returns soft deleted models. + */ + 'subject_returns_soft_deleted_models' => 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, + + /* + * This is the name of the table that will be created by the migration and + * used by the Activity model shipped with this package. + */ + 'table_name' => env('ACTIVITY_LOGGER_TABLE_NAME', 'activity_log'), + + /* + * This is the database connection that will be used by the migration and + * the Activity model shipped with this package. In case it's not set + * Laravel's database.default will be used instead. + */ + 'database_connection' => env('ACTIVITY_LOGGER_DB_CONNECTION'), +]; diff --git a/database/migrations/2025_10_31_144909_create_activity_log_table.php b/database/migrations/2025_10_31_144909_create_activity_log_table.php new file mode 100644 index 0000000..b788f65 --- /dev/null +++ b/database/migrations/2025_10_31_144909_create_activity_log_table.php @@ -0,0 +1,27 @@ +create(config('activitylog.table_name'), function (Blueprint $table) { + $table->bigIncrements('id'); + $table->string('log_name')->nullable(); + $table->text('description'); + $table->nullableMorphs('subject', 'subject'); + $table->nullableMorphs('causer', 'causer'); + $table->json('properties')->nullable(); + $table->timestamps(); + $table->index('log_name'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name')); + } +} diff --git a/database/migrations/2025_10_31_144910_add_event_column_to_activity_log_table.php b/database/migrations/2025_10_31_144910_add_event_column_to_activity_log_table.php new file mode 100644 index 0000000..78d9a0e --- /dev/null +++ b/database/migrations/2025_10_31_144910_add_event_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +table(config('activitylog.table_name'), function (Blueprint $table) { + $table->string('event')->nullable()->after('subject_type'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) { + $table->dropColumn('event'); + }); + } +} diff --git a/database/migrations/2025_10_31_144911_add_batch_uuid_column_to_activity_log_table.php b/database/migrations/2025_10_31_144911_add_batch_uuid_column_to_activity_log_table.php new file mode 100644 index 0000000..320ef5c --- /dev/null +++ b/database/migrations/2025_10_31_144911_add_batch_uuid_column_to_activity_log_table.php @@ -0,0 +1,22 @@ +table(config('activitylog.table_name'), function (Blueprint $table) { + $table->uuid('batch_uuid')->nullable()->after('properties'); + }); + } + + public function down() + { + Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) { + $table->dropColumn('batch_uuid'); + }); + } +}