Skip to content

Commit 6fb2df1

Browse files
authored
Support spaces between JSON key/value (#12)
When using a `json` database column spaces are added between a key and value. When using a `text` database column NO spaces are added between a key and value. (= default output of `json_encode`)
1 parent c2e1582 commit 6fb2df1

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/UniqueTranslationValidator.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ protected function isUnique($value, $name, $locale, $parameters)
229229
*/
230230
protected function findTranslation($connection, $table, $column, $locale, $value)
231231
{
232-
return DB::connection($connection)->table($table)->where($column, 'LIKE', "%\"{$locale}\":\"{$value}\"%");
232+
return DB::connection($connection)->table($table)
233+
->where(function ($query) use ($column, $locale, $value) {
234+
$query->where($column, 'LIKE', "%\"{$locale}\": \"{$value}\"%")
235+
->orWhere($column, 'LIKE', "%\"{$locale}\":\"{$value}\"%");
236+
});
233237
}
234238

235239
/**

tests/TestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function setupDatabase()
6666

6767
$this->app['db']->getSchemaBuilder()->create($this->table, function (Blueprint $table) {
6868
$table->increments('id');
69-
$table->text('slug')->nullable();
69+
$table->json('slug')->nullable();
7070
$table->text('name')->nullable();
7171
$table->string('other_field')->nullable();
7272
});

0 commit comments

Comments
 (0)