Events
SlugChanged
Polyslug\Events\SlugChanged — dispatched when a model's current slug is created or
changed for a locale. Always on.
| Property | Type | Description |
|---|---|---|
model | Illuminate\Database\Eloquent\Model | The model whose slug changed. |
locale | string | The locale the slug belongs to. |
slug | string | The new current slug. |
previous | ?string | The superseded slug, or null on first generation. |
use Polyslug\Events\SlugChanged;
Event::listen(function (SlugChanged $event) {
// cache busting, search reindexing, sitemap regeneration
});
A backfill fires one per row, which is worth knowing before you attach expensive work to it.
SlugRedirected
Polyslug\Events\SlugRedirected — dispatched when the canonical middleware self-heals a
stale slug. Only when polyslug.analytics.enabled is true.
| Property | Type | Description |
|---|---|---|
model | Polyslug\Contracts\Sluggable | The model the request resolved to. |
requested | string | The stale route key the visitor asked for. |
canonicalUrl | string | The URL they are being redirected to. |
locale | string | The locale the redirect was built for. |
status | int | The redirect status actually sent. |
It is keyed on the stable model rather than on the churny slug, so a rename does not double-count. It fires for the self-healing redirect only — not for a gone or superseded response.
SlugReclaimed
Polyslug\Events\SlugReclaimed — dispatched when a
reclaimActive model takes a slug away from
the record that was actively holding it. Only fires when there was somebody to displace.
| Property | Type | Description |
|---|---|---|
claimant | Illuminate\Database\Eloquent\Model | The model that took the name. |
locale | string | The locale the name was taken in. |
slug | string | The name that changed hands. |
previousOwnerType | string | Morph type of the displaced record. |
previousOwnerId | string | Primary key of the displaced record. |
use Polyslug\Events\SlugReclaimed;
Event::listen(function (SlugReclaimed $event) {
// The displaced record has NO current slug for this locale until its own
// source is synced. Re-sync it from your upstream, or call polyslugSync().
});
The previous owner is named by type and key rather than handed over as a model: loading it would cost a query on every takeover, and it would bypass whatever resolution gate that model has. You are better placed to decide both.
It is dispatched after the transaction commits and only for the write that actually landed, so a listener never reacts to a handover that was rolled back.
All three classes are final readonly, so the payload is immutable in a listener.