Writes and deletes dispatch events you can listen to for audit trails and integrations:
| Event | Properties | Fires on |
|---|---|---|
OptionSet | key, value, owner | set() — every write path, including setMany(), groups and remember() when it stores. |
OptionForgotten | key, owner | forget() and reset(). |
OptionResolved | key, value, owner | Every read, memo hits included — only with events.resolved enabled. |
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Options\Events\OptionForgotten;
use RoundlyConsulting\Options\Events\OptionSet;
Event::listen(OptionSet::class, function (OptionSet $event): void {
logger()->info('Option changed', [
'key' => $event->key,
'owner' => $event->owner?->getKey(),
]);
});
Event::listen(OptionForgotten::class, function (OptionForgotten $event): void {
// $event->key, $event->owner
});Switches
OPTIONS_EVENTS_ENABLED=true # OptionSet + OptionForgotten (and observers)
OPTIONS_EVENTS_RESOLVED=true # also OptionResolved on every read- All three events need options.events.enabled (on by default). OptionResolved also needs options.events.resolved — it fires on every read, so it’s off by default.
- OptionSet and OptionResolved carry the cast value — the same value get() returns. For encrypted options that’s the plain value — keep it out of logs.
- Events are dispatched synchronously; queue your listener if the work is slow.
- Observers and live config overrides are built on OptionSet and OptionForgotten, so turning events off silences them too.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.