github happytodev/blogr v2.7.6
2.7.6 — a post slug is unique per locale

one hour ago

Blogr 2.7.6

A post slug is now unique per locale, which is what the route always implied.

The bug

blog_post_translations declared unique('slug'): the English and the French version of one article
could not share a slug. The second one was refused by the admin with "already taken", and the only way
out was to invent different slugs (af-01-day-11-en / af-01-day-11-fr) for two URLs that were
already distinct — the locale is part of the route.

Categories, tags and CMS pages were already unique(['locale', 'slug']); posts were the exception.

The fix

  • A migration replaces the global index with unique(['locale', 'slug']).
  • The admin slug rule is scoped to the item's locale: the same slug in another locale is accepted, a
    duplicate inside the same locale is still refused.
  • BlogController::show() fell back on "find by slug alone" when the requested locale had no match.
    With two locales able to own the same slug, that fallback would answer with another language's
    article under this locale. It now applies only when the post has no translation in the requested
    locale, and not at all when locales are out of the URL (nothing then claims a language, so a slug
    resolves to its translation as before).

Regression tests

  • tests/Localized/regression_365_per_locale_post_slug.php — same slug in two locales, each URL serves
    its own content; the legacy flat link still resolves; a foreign post never answers for another.
  • tests/Feature/Filament/Regression365LocaleScopedSlugTest.php — the admin accepts the slug in the
    other locale and still refuses it twice in the same one.

Each was checked against the previous code: with the migration removed the suite answers
UNIQUE constraint failed: blog_post_translations.slug; with the old fallback restored the mixed-locale
URL answers 200 instead of 404; with the rule left global the admin refuses the shared slug.

Upgrade

composer require happytodev/blogr:^2.7.6
php artisan migrate

One migration: it drops the global unique index and adds (locale, slug).

Don't miss a new blogr release

NewReleases is sending notifications on new releases.