The gap
Renaming a post or product in Laravel changes its URL, and every link in search results, newsletters and other sites starts returning 404 unless someone adds redirects by hand.
Plugins
Rename a post or product and its old links keep working: one trait stores old slugs and answers them with a single 301 to the current URL, no route changes.
Coming soon
Not published on its store yet, so there is no buy or download link. PN Scripts does not take payment for it here.
The gap
Renaming a post or product in Laravel changes its URL, and every link in search results, newsletters and other sites starts returning 404 unless someone adds redirects by hand.
What it is
Trailmark records old slugs automatically and redirects them to the current URL through the route binding you already have.
How you use it
One trait and one migration replace a hand-kept redirect list for model URLs, with loops ruled out by design.
For Laravel developers running blogs, shops and content sites whose editors rename things and expect old links to keep working.
Use it when
Built for
After every save the trait compares the slug column with its previous value. If it changed, the previous slug is stored in the slug_history table with the model type and key. If the new slug matches an old slug of the same model type, that history entry is removed, because a live slug always takes precedence.
The trait extends route model binding. When the normal lookup by slug finds nothing, Trailmark looks in the history and answers with a redirect to the same route with the current slug, keeping the query string and other parameters. Controllers that look models up themselves can call findBySlugOrRedirect().
Old slugs point at the model, never at another slug, so there are no chains. Renaming back removes the slug from the history, a request that would redirect to its own URL gets the normal 404, soft-deleted models do not redirect, and only GET and HEAD requests are redirected.
Each old slug counts its hits and the time of the last one. The trailmark:prune command deletes entries recorded too long ago, entries nobody requested for a given number of days, entries beyond a per-model limit and entries whose model no longer exists. A dry run shows the counts first, and the command can run from the scheduler.
1 of 5
| Platform or runtime | Supported versions | Tested up to |
|---|---|---|
| Laravel | 12.0 or newer | 13.35.0 |
| PHP | 8.2 or newer | 8.4.26 |
It is finished and tested. It is not on sale yet; this page will say where to get it when it is.
Coming soon
Not published on its store yet, so there is no buy or download link. PN Scripts does not take payment for it here.