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.
Install the package:
composer require lara-igniter/activitylogAdd the provider to config/hooks.php before application providers:
Laraigniter\Activitylog\ActivitylogServiceProvider::class,The activity log table is required. Publish the package migration:
php artisan vendor:publish --tag=activitylog-migrationsThen run the migration:
php artisan migrateThe package loads its bundled defaults automatically. Publish an editable application override only when needed:
php artisan vendor:publish --tag=activitylog-configThe 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.
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.
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.
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_idMultiple relations are supported: ->logMorphs(['emailable', 'receiptable']). The activity-log UI can render every configured relation without model-specific conditions.
$activities = (new Laraigniter\Activitylog\Models\Activity())
->inLog('receipts')
->forEvent('updated')
->latest()
->all();
(new Laraigniter\Activitylog\Actions\CleanActivityLogAction())->execute();Clean records older than the configured clean_after_days value:
php artisan activitylog:cleanOverride the retention period or clean one named log only:
php artisan activitylog:clean --days=90
php artisan activitylog:clean receipts --days=90Delete 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.