koenhoeijmakers /
laravel-translatable
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace KoenHoeijmakers\LaravelTranslatable\Scopes; |
||||
| 6 | |||||
| 7 | use Illuminate\Database\Eloquent\Builder; |
||||
| 8 | use Illuminate\Database\Eloquent\Model; |
||||
| 9 | use Illuminate\Database\Eloquent\Scope; |
||||
| 10 | use Illuminate\Database\Query\JoinClause; |
||||
| 11 | |||||
| 12 | class JoinTranslationScope implements Scope |
||||
| 13 | { |
||||
| 14 | /** |
||||
| 15 | * Apply the scope to a given Eloquent query builder. |
||||
| 16 | * |
||||
| 17 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||||
| 18 | * @param \Illuminate\Database\Eloquent\Model|\KoenHoeijmakers\LaravelTranslatable\HasTranslations $model |
||||
| 19 | * @return void |
||||
| 20 | */ |
||||
| 21 | 24 | public function apply(Builder $builder, Model $model) |
|||
| 22 | { |
||||
| 23 | $builder->leftJoin($model->getTranslationTable(), function (JoinClause $join) use ($model) { |
||||
| 24 | 24 | $join->on( |
|||
| 25 | 24 | $model->getTable() . '.' . $model->getKeyName(), |
|||
| 26 | 24 | $model->getTranslationTable() . '.' . $model->getForeignKey() |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 27 | 24 | )->where($model->getLocaleKeyName(), $model->getLocale()); |
|||
|
0 ignored issues
–
show
It seems like
$model->getLocaleKeyName() can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $column of Illuminate\Database\Query\Builder::where() does only seem to accept Closure|array|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 28 | 24 | })->addSelect($model->getTable() . '.*', ...$model->formatTranslatableColumnsForSelect()); |
|||
| 29 | 24 | } |
|||
| 30 | } |
||||
| 31 |