> For the complete documentation index, see [llms.txt](https://pckg.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pckg.gitbook.io/documentation/core-packages/index-4/events.md).

# Events

Across the code, there are different events allowing you to subscribe to them:

* `Record::class.inserting`
* `Record::class.inserted`
* `Record::class.updating`
* `Record::class.updated`
* `Record::class.deleting`
* `Record::class.deleted`
* * `static::class...` - all global `Record::class` events also have their local `static::class` events, for example `User::class.inserting`

## Adding a handler

You can register a handler in any of your providers:

```php
<?php

namespace Vendor\Domain\Provider;

use Pckg\Framework\Provider;
use Vendor\Domain\Record\User;
use Vendor\Domain\Handler\LogUserInserted;

class MyProvider extends Provider
{
    public function listeners()
    {
        return [
            User::class . '.inserted' => [
                LogUserInserted::class,
            ],
        ];
    }
}
```

And then implement your event handler:

```php
<?php

namespace Vendor\Domain\Handler;

class LogUserInserted
{
    public function __construct(protected User $user) { }

    public function handle()
    {
        error_log('User ' . $this->user->id . ' inserted.');
    }
}
```
