1 | <?php |
||||||
2 | |||||||
3 | namespace Locale\Database; |
||||||
4 | |||||||
5 | use Illuminate\Database\Eloquent\Builder; |
||||||
6 | use Locale\Models\Localizable; |
||||||
7 | |||||||
8 | class LocalizableBuilder extends Builder |
||||||
9 | { |
||||||
10 | /** |
||||||
11 | * @var bool |
||||||
12 | */ |
||||||
13 | protected $translationJoined = false; |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Add an "order by" clause to the query. |
||||||
17 | * |
||||||
18 | * @param string $column |
||||||
19 | * @param string $direction |
||||||
20 | * @return Builder|LocalizableBuilder |
||||||
21 | */ |
||||||
22 | public function orderBy($column, $direction = 'asc') |
||||||
23 | { |
||||||
24 | /** @var Localizable $localizableModel */ |
||||||
25 | $localizableModel = $this->model; |
||||||
26 | |||||||
27 | if ($localizableModel->isLocalizableAttribute($column)) { |
||||||
28 | $this->joinWithTranslation(); |
||||||
29 | } |
||||||
30 | |||||||
31 | return parent::orderBy($column, $direction); |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
32 | } |
||||||
33 | |||||||
34 | /** |
||||||
35 | * @since 1.0.0 |
||||||
36 | */ |
||||||
37 | public function joinWithTranslation() |
||||||
38 | { |
||||||
39 | if (!$this->translationJoined) { |
||||||
40 | /** @var Localizable $localizableModel */ |
||||||
41 | $localizableModel = $this->model; |
||||||
42 | |||||||
43 | $localeTable = config("locale.model"); |
||||||
44 | $modelTable = $localizableModel->getTable(); |
||||||
45 | $modelKeyName = $localizableModel->getKeyName(); |
||||||
46 | $joiningTable = $localizableModel->joiningLocaleTable($localeTable, $modelTable); |
||||||
47 | $modelForeignKey = $localizableModel->getModelForeignKey(); |
||||||
48 | |||||||
49 | $this->join($joiningTable, "{$modelTable}.{$modelKeyName}", "=", "{$joiningTable}.{$modelForeignKey}"); |
||||||
0 ignored issues
–
show
The method
join() does not exist on Locale\Database\LocalizableBuilder . Since you implemented __call , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
50 | } |
||||||
51 | } |
||||||
52 | } |
||||||
53 |