@@ -18,18 +18,18 @@ discard block |
||
18 | 18 | { |
19 | 19 | static::addGlobalScope(new TranslatableScope); |
20 | 20 | |
21 | - static::saving(function ($model) { |
|
21 | + static::saving(function($model) { |
|
22 | 22 | $model->translatable = collect($model->attributes)->only(static::$transtableFieldName)->toArray(); |
23 | 23 | $model->attributes = collect($model->attributes)->except(static::$transtableFieldName)->toArray(); |
24 | 24 | }); |
25 | 25 | |
26 | - static::saved(function ($model) { |
|
26 | + static::saved(function($model) { |
|
27 | 27 | if ($model->translatable) { |
28 | 28 | (new self)->saveTranslation($model); |
29 | 29 | } |
30 | 30 | }); |
31 | 31 | |
32 | - static::deleted(function ($model) { |
|
32 | + static::deleted(function($model) { |
|
33 | 33 | if ((new $model)->has('translations')) { |
34 | 34 | $model->translations()->delete(); |
35 | 35 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | // Build the sub select |
69 | - $fields->each(function ($key) use ($query) { |
|
69 | + $fields->each(function($key) use ($query) { |
|
70 | 70 | $this->subSelectTranslation($query, $key); |
71 | 71 | }); |
72 | 72 | |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | protected function subSelectTranslation($query, $key): void |
77 | 77 | { |
78 | 78 | $query->addSelect([ |
79 | - $key => function ($query) use ($key) { |
|
80 | - $query->select(Translation::getTableName() . '.value') |
|
79 | + $key => function($query) use ($key) { |
|
80 | + $query->select(Translation::getTableName().'.value') |
|
81 | 81 | ->from(Translation::getTableName()) |
82 | - ->where(Translation::getTableName() . '.translatable_type', '=', \get_class($this)) |
|
83 | - ->where(Translation::getTableName() . '.locale', '=', $this->locale) |
|
84 | - ->where(Translation::getTableName() . '.key', '=', $key) |
|
85 | - ->where(Translation::getTableName() . '.translatable_id', '=', \DB::raw($this->getTable() . '.' . $this->primaryKey)); |
|
82 | + ->where(Translation::getTableName().'.translatable_type', '=', \get_class($this)) |
|
83 | + ->where(Translation::getTableName().'.locale', '=', $this->locale) |
|
84 | + ->where(Translation::getTableName().'.key', '=', $key) |
|
85 | + ->where(Translation::getTableName().'.translatable_id', '=', \DB::raw($this->getTable().'.'.$this->primaryKey)); |
|
86 | 86 | } |
87 | 87 | ]); |
88 | 88 | |
@@ -105,10 +105,10 @@ discard block |
||
105 | 105 | { |
106 | 106 | $table = Translation::getTableName(); |
107 | 107 | |
108 | - return DB::table($table)->select($table . '.key') |
|
109 | - ->where($table . '.translatable_type', \get_class($this)) |
|
110 | - ->where($table . '.locale', $this->locale) |
|
111 | - ->groupBy($table . '.key') |
|
108 | + return DB::table($table)->select($table.'.key') |
|
109 | + ->where($table.'.translatable_type', \get_class($this)) |
|
110 | + ->where($table.'.locale', $this->locale) |
|
111 | + ->groupBy($table.'.key') |
|
112 | 112 | ->pluck('key'); |
113 | 113 | } |
114 | 114 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | |
124 | 124 | protected function fullTextWildcards($term) |
125 | 125 | { |
126 | - return collect(explode(' ', str_replace(['-', '+', '<', '>', '@', '(', ')', '~'], '', $term)))->map(function ($word, $key) { |
|
127 | - return strlen($word) >= 3 ? '+' . $word . '*' : ''; |
|
126 | + return collect(explode(' ', str_replace(['-', '+', '<', '>', '@', '(', ')', '~'], '', $term)))->map(function($word, $key) { |
|
127 | + return strlen($word) >= 3 ? '+'.$word.'*' : ''; |
|
128 | 128 | })->implode(' '); |
129 | 129 | } |
130 | 130 | |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | { |
133 | 133 | return $query->join('translations', 'translations.translatable_id', '=', 'products.id') |
134 | 134 | ->addSelect([ |
135 | - 'relevance' => function ($query) use ($term) { |
|
136 | - $query->selectRaw("MATCH (`translations`.`value`) AGAINST ('" . $this->fullTextWildcards($term) . "' IN BOOLEAN MODE)") |
|
135 | + 'relevance' => function($query) use ($term) { |
|
136 | + $query->selectRaw("MATCH (`translations`.`value`) AGAINST ('".$this->fullTextWildcards($term)."' IN BOOLEAN MODE)") |
|
137 | 137 | ->from('translations') |
138 | - ->where('translations.translatable_id', DB::raw($this->getTable() . '.' . $this->primaryKey)) |
|
138 | + ->where('translations.translatable_id', DB::raw($this->getTable().'.'.$this->primaryKey)) |
|
139 | 139 | ->limit(1); |
140 | 140 | } |
141 | 141 | ]) |