Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Translatable Laravel Package

astrotomic/laravel-translatable

Laravel package for translatable Eloquent models. Store model translations in the database and automatically fetch/save multilingual attributes based on locale, reducing boilerplate when working with multi-language content.

View on GitHub
Deep Wiki
Context7

Validating Unique and Exists Rule

You can use custom rules to validate unique and exists rules for translatable attributes.

TranslatableUnique

Ensure that the attribute value is unique by checking its absence in the database; if the value already exists, raise a validation exception.

Option 1
use Astrotomic\Translatable\Validation\Rules\TranslatableUnique;
...

$person = new Person(['name' => 'john doe']);
$person->save();

$data = [
    'name' => 'john doe',
    'email' => 'john@example.com'
];
$validator = Validator::make($data, [
    'name' => ['required', new TranslatableUnique(Person::class, 'name')],
]);

Option 2
use Astrotomic\Translatable\Validation\Rules\TranslatableUnique;
...

$person = new Person(['name' => 'john doe']);
$person->save();

$data = [
    'name:en' => 'john doe',
    'email' => 'john@example.com'
];

$validator = Validator::make($data, [
    'name:en' => ['required', Rule::translatableUnique(Person::class, 'name:en')],
]);

Option 2
use Illuminate\Validation\Rule;
...

$person = new Person(['name' => 'john doe']);
$person->save();

$data = [
    'name:en' => 'john doe',
    'email' => 'john@example.com'
];

$validator = Validator::make($data, [
    'name:en' => ['required', Rule::translatableUnique(Person::class, 'name:en')],
]);

TranslatableExists

Verify if the attribute value exists by confirming its presence in the database; if the value does not exist, raise a validation exception.

Option 1
use Astrotomic\Translatable\Validation\Rules\TranslatableExists;
...

$person = new Person(['name' => 'john doe']);
$person->save();

$data = [
    'name' => 'john doe',
    'email' => 'john@example.com'
];
$validator = Validator::make($data, [
    'name' => ['required', new TranslatableExists(Person::class, 'name')],
]);
Option 2
use Illuminate\Validation\Rule;
...

$person = new Person(['name' => 'john doe']);
$person->save();

$data = [
    'name:en' => 'john doe',
    'email' => 'john@example.com'
];

$validator = Validator::make($data, [
    'name:en' => ['required', Rule::translatableExists(Person::class, 'name:en')],
]);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope