Skip to content

Commit fa28870

Browse files
Merge pull request #509 from CheesyTech/main
Added support for translation via JSON fields for PostgreSQL
2 parents 7f7bc48 + 73e9465 commit fa28870

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/HasTags.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Database\Eloquent\Relations\MorphPivot;
1010
use Illuminate\Database\Eloquent\Relations\MorphToMany;
1111
use Illuminate\Support\Arr;
12+
use Illuminate\Support\Facades\DB;
1213
use InvalidArgumentException;
1314

1415
trait HasTags
@@ -70,8 +71,8 @@ public function tagsTranslated(string | null $locale = null): MorphToMany
7071
->morphToMany(self::getTagClassName(), $this->getTaggableMorphName(), $this->getTaggableTableName())
7172
->using($this->getPivotModelClassName())
7273
->select('*')
73-
->selectRaw("JSON_UNQUOTE(JSON_EXTRACT(name, '$.\"{$locale}\"')) as name_translated")
74-
->selectRaw("JSON_UNQUOTE(JSON_EXTRACT(slug, '$.\"{$locale}\"')) as slug_translated")
74+
->selectRaw($this->getQuery()->getGrammar()->wrap("name->{$locale} as name_translated"))
75+
->selectRaw($this->getQuery()->getGrammar()->wrap("slug->{$locale} as slug_translated"))
7576
->ordered();
7677
}
7778

0 commit comments

Comments
 (0)