Skip to content

Commit 14335e3

Browse files
committed
v11.11.0
1 parent 2a7e74a commit 14335e3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## v11
44

5+
### v11.11.0
6+
7+
- Change `\Astrotomic\Translatable\Traits\Relationship::translation()` relation to use the new `ofMany` - [#297](https://github.com/Astrotomic/laravel-translatable/pull/297)
8+
59
### v11.10.0
610

711
- Drop PHP7 support

src/Translatable/Traits/Relationship.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Astrotomic\Translatable\Traits;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Database\Eloquent\Relations\HasMany;
67
use Illuminate\Database\Eloquent\Relations\HasOne;
78

@@ -67,7 +68,7 @@ public function translation(): HasOne
6768
->hasOne($this->getTranslationModelName(), $this->getTranslationRelationKey())
6869
->ofMany([
6970
$this->getTranslationRelationKey() => 'max',
70-
], function ($query) {
71+
], function (Builder $query): void {
7172
$query->where($this->getLocaleKey(), $this->localeOrFallback());
7273
});
7374
}

tests/TranslatableTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,10 @@ public function translation_relation(): void
804804
$this->app->make('config')->set('translatable.use_fallback', true);
805805
$this->app->setLocale('en');
806806

807-
$peas = factory(Vegetable::class)->create(['name:en' => 'Peas']);
807+
$peas = factory(Vegetable::class)->create([
808+
'name:en' => 'Peas',
809+
'name:fr' => 'Pois',
810+
]);
808811

809812
static::assertInstanceOf(VegetableTranslation::class, $peas->translation);
810813
static::assertEquals('en', $peas->translation->locale);
@@ -819,6 +822,7 @@ public function translation_relation_can_use_fallback_locale(): void
819822

820823
$peas = factory(Vegetable::class)->create(['name:fr' => 'Pois']);
821824

825+
static::assertInstanceOf(VegetableTranslation::class, $peas->translation);
822826
static::assertEquals('fr', $peas->translation->locale);
823827
}
824828

0 commit comments

Comments
 (0)