Every event is a final readonly class in RoundlyConsulting\Tags\Events implementing ShouldDispatchAfterCommit — it fires only once the change committed, never for a rollback:
| Event | Payload | Fires when |
|---|---|---|
Tagged | taggable, tags | Tags were attached to a model (attach or sync) — only when something changed. |
Untagged | taggable, tags | Tags were detached (detach, sync, clear, a force-deleted taggable) — only when something changed. |
TagCreated | tag | A tag was created — through the catalog, or for a new free-form name while tagging. |
TagUpdated | tag, changed | Name, description, slug, colour or icon changed; changed lists which. |
TagMoved | tag, from, to | A new parent or a new position; from / to are the old and new parent (null: root). A move to where the tag already is fires nothing. |
TagsReordered | type, parent, tags | Siblings under a parent (the roots when null) were reordered — at least one position changed; tags in their new order. |
TagDeleted | tag, detached, subtree | A tag (and with TagChildren::Delete its subtree) was deleted and detached everywhere; detached counts the taggings removed. Fires once — of two concurrent deletes, the second returns the deleted tag and fires nothing. No per-model Untagged fires. |
TagMerged | from, into, moved, deduplicated, reparented, deleted | A tag was merged into another (merge()): its taggings moved to into, from was deleted. reparented lists its children now under into (TagChildren::Reparent), deleted the descendants deleted with it (TagChildren::Delete). The only event a merge fires — no TagDeleted, no TagMoved, no per-model Tagged or Untagged; of two concurrent merges of one tag, the refused one fires nothing. |
TagRestored | tag | A deleted tag came back — restore(), or a create, findOrCreate, attach or sync of a name it held. It carries no taggings. |
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Tags\Events\TagDeleted;
use RoundlyConsulting\Tags\Events\Tagged;
use RoundlyConsulting\Tags\Events\Untagged;
Event::listen(function (Tagged $event): void {
// $event->taggable — the model; $event->tags — list<Tag> this write attached
});
Event::listen(function (Untagged $event): void {
// $event->tags — list<Tag> this write detached (a detach, a sync, a clear, a force delete)
});
// A deleted tag fires no per-model Untagged: react to it once, here
Event::listen(function (TagDeleted $event): void {
// $event->tag, $event->detached (taggings removed), $event->subtree (tags deleted with it)
});- Tagged and Untagged fire once per write, with every tag it attached or detached — never for a call that changed nothing.
- Every catalog event fires only when something changed: a move to where the tag already is, a reorder to the current order, an update that changes nothing, a restore of a live tag or a delete of a deleted tag fires nothing.
- A tag deleted through the catalog detaches it everywhere in one statement and fires one TagDeleted, not an Untagged per model.
- A merge fires TagMerged only: no TagDeleted for the merged tag or its subtree, no TagMoved for a reparented child, no per-model Tagged or Untagged. Of two concurrent merges of one tag, the second is refused and fires nothing.
- Tags::fake() does not fake events — every call still runs — so Event::fake() works next to it.
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.