From 14335e33189a0902941a9795f744dea2a4a929f1 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Mon, 10 Oct 2022 14:35:52 +0200 Subject: [PATCH] v11.11.0 --- docs/changelog.md | 4 ++++ src/Translatable/Traits/Relationship.php | 3 ++- tests/TranslatableTest.php | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index b08e9f2..caa48e3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,10 @@ ## v11 +### v11.11.0 + +- Change `\Astrotomic\Translatable\Traits\Relationship::translation()` relation to use the new `ofMany` - [#297](https://github.com/Astrotomic/laravel-translatable/pull/297) + ### v11.10.0 - Drop PHP7 support diff --git a/src/Translatable/Traits/Relationship.php b/src/Translatable/Traits/Relationship.php index 77f41cd..606368a 100644 --- a/src/Translatable/Traits/Relationship.php +++ b/src/Translatable/Traits/Relationship.php @@ -2,6 +2,7 @@ namespace Astrotomic\Translatable\Traits; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -67,7 +68,7 @@ public function translation(): HasOne ->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey()) ->ofMany([ $this->getTranslationRelationKey() => 'max', - ], function ($query) { + ], function (Builder $query): void { $query->where($this->getLocaleKey(), $this->localeOrFallback()); }); } diff --git a/tests/TranslatableTest.php b/tests/TranslatableTest.php index 2934a05..a5b2162 100644 --- a/tests/TranslatableTest.php +++ b/tests/TranslatableTest.php @@ -804,7 +804,10 @@ public function translation_relation(): void $this->app->make('config')->set('translatable.use_fallback', true); $this->app->setLocale('en'); - $peas = factory(Vegetable::class)->create(['name:en' => 'Peas']); + $peas = factory(Vegetable::class)->create([ + 'name:en' => 'Peas', + 'name:fr' => 'Pois', + ]); static::assertInstanceOf(VegetableTranslation::class, $peas->translation); static::assertEquals('en', $peas->translation->locale); @@ -819,6 +822,7 @@ public function translation_relation_can_use_fallback_locale(): void $peas = factory(Vegetable::class)->create(['name:fr' => 'Pois']); + static::assertInstanceOf(VegetableTranslation::class, $peas->translation); static::assertEquals('fr', $peas->translation->locale); }