diff --git a/src/HasTags.php b/src/HasTags.php index 4f5b24c..a5b1076 100644 --- a/src/HasTags.php +++ b/src/HasTags.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\MorphPivot; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Support\Arr; +use Illuminate\Support\Facades\DB; use InvalidArgumentException; trait HasTags @@ -70,8 +71,8 @@ public function tagsTranslated(string | null $locale = null): MorphToMany ->morphToMany(self::getTagClassName(), $this->getTaggableMorphName(), $this->getTaggableTableName()) ->using($this->getPivotModelClassName()) ->select('*') - ->selectRaw("JSON_UNQUOTE(JSON_EXTRACT(name, '$.\"{$locale}\"')) as name_translated") - ->selectRaw("JSON_UNQUOTE(JSON_EXTRACT(slug, '$.\"{$locale}\"')) as slug_translated") + ->selectRaw($this->getQuery()->getGrammar()->wrap("name->{$locale} as name_translated")) + ->selectRaw($this->getQuery()->getGrammar()->wrap("slug->{$locale} as slug_translated")) ->ordered(); }