- How do I install and use codezero/laravel-unique-translation in a Laravel app?
- Install it with Composer using composer require codezero/laravel-unique-translation. Laravel package auto-discovery registers the service provider, so no manual provider wiring is normally needed. Add the UniqueTranslationRule class or the string-form unique_translation rule to the relevant FormRequest or Validator rules, passing the JSON column and locale key according to the package README. Basic use does not require migrations or config publishing.
- Does this package work with spatie/laravel-translatable JSON columns?
- Yes, it targets the JSON-in-a-column storage pattern commonly produced by spatie/laravel-translatable, such as a title column containing locale keys like en and fr. It does not require spatie/laravel-translatable as a dependency, but it does assume translated values live inside a JSON document rather than in a normalized translations table. If your translations are stored differently, this rule is not the right fit.
- Which database drivers are supported for the JSON-path uniqueness query?
- The rule resolves to a JSON-path where clause, so behavior depends on your database driver. MySQL 5.7/8, PostgreSQL json versus jsonb, SQLite, and SQL Server differ in JSON-path support and semantics. An unsupported path syntax can fail at query time rather than at application boot, so test the rule against your actual production driver before relying on it.
- Can I scope uniqueness to a tenant, parent record, or ignore soft-deleted rows?
- No, tenant scoping, parent-record scoping, publish state, ignore-by-ID, and withTrashed behavior are not first-class features in the package. If your uniqueness domain is unique per tenant or unique among non-archived records, you will need to extend or wrap the rule. That wrapping is where subtle mismatches between validation and domain rules tend to appear, so cover it with tests.
- Does this validation rule prevent duplicate translations under concurrent requests?
- No, validation uniqueness is advisory and subject to a check-then-insert race. Two concurrent requests can both pass validation and both persist the same translated value. To truly prevent duplicates you need a database-level guarantee such as a functional or expression index on the JSON path where supported, or an application-level lock around the write.
- Do I need an index on the JSON path for performance?
- Performance depends heavily on whether a functional or expression index exists for the JSON path being validated. Without one, each validation call can scan the target table, which may be acceptable at small row counts but problematic at scale or with high write volume. Document the index requirement as part of your adoption checklist and verify the query plan on your database.
- How are null, empty string, and case or collation differences handled for uniqueness?
- The provided context does not specify the package's exact treatment of nulls, empty strings, or case and collation differences. These behaviors can also vary by database driver and column collation. Test these edge cases explicitly in your environment, especially if your forms allow blank translated values or if case-insensitive uniqueness is a business requirement.
- Which Laravel and PHP versions does codezero/laravel-unique-translation support?
- Exact supported Laravel and PHP versions cannot be confirmed from the provided context because the composer constraints and CI matrix are not included. The technical assessment recommends pairing it with Laravel 9+ and PHP 8.1+ for stack fit. Check the package composer.json and CI configuration before adopting, particularly given the latest release date of 2024-04-17.
- Is this package actively maintained, and what is the adoption risk?
- It is a small single-maintainer package with around 188 stars, zero reported dependents, and a latest release dated 2024-04-17. That makes it a low-risk leaf dependency in architecture terms, but you should not assume it will track Laravel major-version cadence automatically. Confirm the maintainer's release and security-response expectations, and consider vendoring the small rule class if long-term certainty matters.
- What are the alternatives if my database has weak JSON-path support?
- If your database driver handles JSON paths poorly, a normalized translations table with a unique constraint or unique index is usually a better design. You can then use Laravel's built-in unique validation rule against that table, backed by the database constraint. Alternatively, stay with JSON storage only if you can add an expression index and accept the driver-specific behavior.