Search by

lara-igniter / activitylog

giorgosstab

Log activity inside your Laraigniter app.

Package info

github.com/lara-igniter/activitylog

pkg:composer/lara-igniter/activitylog

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.4.0 2026-09-09 09:38 UTC

This package is auto-updated.

Last update: 2026-09-09 09:43:29 UTC


README

Auditable activity logging for Laraigniter applications. It uses Elegant\Database\Model\Model, CodeIgniter config groups, and the existing Laraigniter model-event arrays; it has no Laravel or Eloquent dependency.

Installation

Install the package:

composer require lara-igniter/activitylog

Add the provider to config/hooks.php before application providers:

Laraigniter\Activitylog\ActivitylogServiceProvider::class,

Publish and run the migration

The activity log table is required. Publish the package migration:

php artisan vendor:publish --tag=activitylog-migrations

Then run the migration:

php artisan migrate

Publish the configuration (optional)

The package loads its bundled defaults automatically. Publish an editable application override only when needed:

php artisan vendor:publish --tag=activitylog-config

The published config/activitylog.php is loaded after the package defaults and therefore overrides them. Use --force only when you intentionally want to overwrite an existing published file.

Log an activity explicitly

Pass a Laraigniter model instance and the persisted subject ID. The framework's read results are data objects, so the ID is explicit when logging from a model service/repository.

activity('payments')
    ->event('paid')
    ->performedOn($receiptModel, $receiptId)
    ->withProperty('amount', $amount)
    ->log('Receipt paid');

The authenticated Ion Auth user is attached automatically. Use causedBy() to supply another actor, or causedByAnonymous() to suppress it.

Automatically log model events

Use LogsActivity in an Model class and return its options:

use Laraigniter\Activitylog\Models\Concerns\LogsActivity;
use Laraigniter\Activitylog\Support\LogOptions;

class Receipt extends Model
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logFillable()
            ->logOnlyDirty()
            ->logExcept(['internal_note'])
            ->dontLogEmptyChanges()
            ->useLogName('receipts')
            ->setDescriptionForEvent(static function (string $event): string {
                return "Receipt {$event}";
            });
    }
}

The trait records created, updated, deleted, force_deleted, and restored events. deleted represents a soft delete; force_deleted represents a permanent deletion. For a single-record update, it captures the persisted row before the write and stores Laravel-style changes: new values under attribute_changes.attributes and previous values under attribute_changes.old. With logOnlyDirty(), unchanged attributes are excluded from both collections.

Polymorphic model context

For a logged model with polymorphic columns, declare the relationship prefix with logMorphs(). The type and ID are stored in the activity properties.polymorphic_relations collection, separately from the attribute changes.

return LogOptions::defaults()
    ->logFillable()
    ->logMorphs(['addressable']); // addressable_type and addressable_id

Multiple relations are supported: ->logMorphs(['emailable', 'receiptable']). The activity-log UI can render every configured relation without model-specific conditions.

Query logs and retention

$activities = (new Laraigniter\Activitylog\Models\Activity())
    ->inLog('receipts')
    ->forEvent('updated')
    ->latest()
    ->all();

(new Laraigniter\Activitylog\Actions\CleanActivityLogAction())->execute();

Cleanup command

Clean records older than the configured clean_after_days value:

php artisan activitylog:clean

Override the retention period or clean one named log only:

php artisan activitylog:clean --days=90
php artisan activitylog:clean receipts --days=90

Delete every activity record explicitly, or every record in one named log:

php artisan activitylog:clean --all
php artisan activitylog:clean receipts --all

--all permanently deletes matching activity records and cannot be combined with --days.

Set ACTIVITYLOG_ENABLED=false to stop persistence. The default configuration excludes password and remember_token; extend default_except_attributes for additional sensitive fields.