Skip to main content

Activity Log Formatting

Models implementing DomainObjectContract with HasDomainObject trait get automatic activity logging with customizable formatting.

Custom Labels

Override formatActivityLogAttributeLabel() for custom attribute labels:
public function formatActivityLogAttributeLabel(string $key): ?string
{
    return match ($key) {
        'business_central_environment' => __('Business Central environment'),
        default => null // Auto-generates from key name
    };
}

Custom Values

Override formatActivityLogAttributeValue() for custom value formatting:
public function formatActivityLogAttributeValue(string $key, mixed $value): mixed
{
    return match ($key) {
        'status' => ActivityValueFormatter::enum(OrderStatus::class, $value),
        'customer_id' => ActivityValueFormatter::objectReference(Customer::class, $value),
        'locale' => ['sv' => __('Swedish'), 'en' => __('English')][$value] ?? null,
        default => null // Auto-formats based on model casts
    };
}

Custom Descriptions

Override formatActivityLogDescription() for custom activity descriptions:
public function formatActivityLogDescription(Activity $activity): ?string
{
    return null; // Use default description
}

ActivityValueFormatter Methods

  • enum($enumClass, $value) - Format enums using label() method
  • objectReference($modelClass, $value) - Create linked object references
  • date($value) / datetime($value) - Format dates
  • auto($model, $key, $value) - Auto-format based on model casts

Default Behavior

  • Logs all attributes except timestamps/system fields
  • Auto-generates labels from attribute names
  • Auto-formats dates, enums, and other cast types
  • Only logs dirty (changed) attributes