diff --git a/CHANGELOG.md b/CHANGELOG.md index 2766ce6..b11fac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 4.2.1 (released 2017-02-07) + +- Fix with translations query + ## 4.2.0 (released 2017-02-07) - Added eager loading support diff --git a/src/Translatable.php b/src/Translatable.php index 793bb6b..e91ecb5 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -61,16 +61,16 @@ public function translate(string $locale = null, bool $fallback = true): Model /** * Query scope for eager-loading the translations for current (or a given) locale. * - * @param \Illuminate\Database\Eloquent\Builder $builder + * @param \Illuminate\Database\Eloquent\Builder $query * @param string|null $locale * - * @return void + * @return \Illuminate\Database\Eloquent\Builder */ - public static function scopeWithTranslations(Builder $builder, string $locale = null) + public function scopeWithTranslations(Builder $query, string $locale = null): Builder { - $locale = $locale ?: (new static())->getLocale(); + $locale = $locale ?: $this->getLocale(); - $builder->with(['translations' => function (HasMany $query) use ($locale) { + return $query->with(['translations' => function (HasMany $query) use ($locale) { $query->where('locale', $locale); }]); }