Skip to content

Commit

Permalink
Support PostgreSQL case insensitive queries with ILIKE (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvermeyen committed Feb 4, 2023
1 parent 8163bf2 commit eadaa83
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/UniqueTranslationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,13 @@ protected function findTranslation($connection, $table, $column, $locale, $value
$escaped = DB::getDriverName() === 'sqlite' ? '\\\\' : '\\\\\\\\';
$value = str_replace('\\', $escaped, $value);

// Support PostgreSQL case insensitive queries with ILIKE
$operator = DB::getDriverName() === 'pgsql' ? 'ILIKE' : 'LIKE';

return DB::connection($connection)->table($table)
->where(function ($query) use ($column, $locale, $value) {
$query->where($column, 'LIKE', "%\"{$locale}\": \"{$value}\"%")
->orWhere($column, 'LIKE', "%\"{$locale}\":\"{$value}\"%");
->where(function ($query) use ($column, $operator, $locale, $value) {
$query->where($column, $operator, "%\"{$locale}\": \"{$value}\"%")
->orWhere($column, $operator, "%\"{$locale}\":\"{$value}\"%");
});
}

Expand Down

0 comments on commit eadaa83

Please sign in to comment.