Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Activity Log Laravel Package

noxoua/filament-activity-log

View on GitHub
Deep Wiki
Context7

title: Events permalink: /events nav_order: 8

Events


Manual Event Logging:

In addition to automatic event logging, you have the flexibility to manually trigger these events using the Logger class. Here's how to use the manual event logging methods:

  • UserLogger::make($record)->created(): Manually logs a "created" event for the given $record. This can be used to log the creation of a new record.

  • UserLogger::make($old_record, $new_record)->updated(): Manually logs an "updated" event, capturing changes between the $old_record (before the update) and the $new_record (after the update). This allows you to log updates to a record.

  • UserLogger::make($record)->deleted(): Manually logs a "deleted" event for the given $record, indicating that the record has been deleted.

  • UserLogger::make($record)->restored(): Manually logs a "restored" event, typically used when a previously deleted record is restored.

By providing these manual event logging methods, the Logger class offers fine-grained control over when and how specific events are logged, allowing you to capture custom events and changes in your application as needed.

Add a Custom Event

You have the flexibility to add custom events to your UserLogger class to log specific actions or activities in your application. In this example, we've added a custom event called transaction_deposit, which is triggered when a deposit transaction is made.

Here's how you can implement a custom event in your UserLogger class:

  1. Define the custom event method within your UserLogger class. In this case, we've created the transaction_deposit method.
class UserLogger extends Logger
{
    // ...

    public function transaction_deposit($transaction): void
    {
        // Define the attributes you want to log for the event
        $attributes = [
            'amount' => $transaction->amount,
            'additional_info' => $transaction->meta['text'] ?? null,
        ];

        // Log the event with the specified attributes and event name
        $this->log(
            ['old' => [], 'attributes' => $attributes],
            event: 'deposit',
        );
    }
}
  1. To trigger the custom event, you can use the ->transaction_deposit method. This method will log the event with the provided attributes, such as the deposit amount and any additional information:
// Trigger the custom event
UserLogger::make($user_record)->transaction_deposit($transaction);

By following this approach, you can easily extend the functionality of your logger to capture custom events and their associated attributes, enabling you to track specific activities within your application.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky