Skip to main content

Events

SlugChanged

Polyslug\Events\SlugChanged — dispatched when a model's current slug is created or changed for a locale. Always on.

PropertyTypeDescription
modelIlluminate\Database\Eloquent\ModelThe model whose slug changed.
localestringThe locale the slug belongs to.
slugstringThe new current slug.
previous?stringThe 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.

PropertyTypeDescription
modelPolyslug\Contracts\SluggableThe model the request resolved to.
requestedstringThe stale route key the visitor asked for.
canonicalUrlstringThe URL they are being redirected to.
localestringThe locale the redirect was built for.
statusintThe 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.

PropertyTypeDescription
claimantIlluminate\Database\Eloquent\ModelThe model that took the name.
localestringThe locale the name was taken in.
slugstringThe name that changed hands.
previousOwnerTypestringMorph type of the displaced record.
previousOwnerIdstringPrimary 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.