Skip to content

Commit

Permalink
Merge pull request #509 from CheesyTech/main
Browse files Browse the repository at this point in the history
Added support for translation via JSON fields for PostgreSQL
  • Loading branch information
AlexVanderbist authored Oct 3, 2024
2 parents 7f7bc48 + 73e9465 commit fa28870
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/HasTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit fa28870

Please sign in to comment.