codezero-be / laravel-unique-translation

⭐️ Check if a translated value in a JSON column is unique in the database.
MIT License
180 stars 24 forks source link

Unique comparison is case sensitive #8

Open ivanvermeyen opened 4 years ago

ivanvermeyen commented 4 years ago

It seems that the where clause in the unique_translation rule is case sensitive.

https://github.com/codezero-be/laravel-unique-translation/blob/1eb3d56b1f4af36b4985730619838bb124436b81/src/UniqueTranslationValidator.php#L161-L164

According to my Google searches, MySQL is supposed to be case insensitive when using a collation that ends in _ci (I'm using utf8mb4_unicode_ci). But that's not what my tests are saying...

Is anyone else having this issue?

Tahiaji commented 1 year ago

yep

ivanvermeyen commented 1 year ago

Fixed by #22

ivanvermeyen commented 1 year ago

Just for later reference: using a LIKE query seems to be case insensitive too and improves compatibility with other database types than MySQL.

eleftrik commented 6 months ago

@ivanvermeyen

I got the same problem while using UniqueTranslationRule validation rule with Filament. I have a mytable.name translatable field. Here the Filament Resource:

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('name')
                    ->rules([
                        fn (Forms\Get $get) => UniqueTranslationRule::for('mytable', 'name')
                            ->ignore($get('id')),
                    ])
                    ->required(),
            ]);

Validation works pretty well when respecting the case (I cannot use Foo twice), but seems to fail when using different case (I can save a record with name=Foo and another with name=foo using the same locale, but I shouldn't be allowed).

Database is MySQL with utf8mb4_unicode_ci collation.

Am I missing or doing anything wrong?

Thanks!

eleftrik commented 5 months ago

@ivanvermeyen Thanks for reopening the issue

ivanvermeyen commented 5 months ago

@eleftrik I'm a bit lost tho as why this is not working. My tests claim that its working and when I manually try it in my own project it works too. I'm not using Filament tho. For the Filament compatibility I've been trusting people's contributions.