stan errors
This commit is contained in:
@@ -42,18 +42,21 @@ class AppServiceProvider extends ServiceProvider
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
Builder::macro('orderByTranslation', function (string $field, string $order = 'asc', ?string $locale = null) {
|
||||
/** @var \Illuminate\Database\Eloquent\Builder */
|
||||
$builder = $this; // @phpstan-ignore-line
|
||||
|
||||
if (
|
||||
in_array(HasTranslations::class, class_uses($this->model))
|
||||
&& in_array($field, $this->model->translatable)
|
||||
in_array(HasTranslations::class, class_uses($builder->model)) // @phpstan-ignore-line
|
||||
&& in_array($field, $builder->model->translatable)
|
||||
&& config('database.default') === 'pgsql'
|
||||
) {
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
$this->query->orderByRaw("$field->>'$locale' $order");
|
||||
$builder->query->orderByRaw("$field->>'$locale' $order");
|
||||
} else {
|
||||
$this->query->orderBy($field, $order);
|
||||
$builder->query->orderBy($field, $order);
|
||||
}
|
||||
|
||||
return $this;
|
||||
return $builder;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user