@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $model = new static; |
79 | 79 | |
80 | - return static::unguarded(function () use ($model, $attributes, $translations){ |
|
80 | + return static::unguarded(function() use ($model, $attributes, $translations){ |
|
81 | 81 | return $model->create($attributes, $translations); |
82 | 82 | }); |
83 | 83 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | { |
94 | 94 | $model = new static; |
95 | 95 | |
96 | - return static::unguarded(function () use ($locale, $model, $attributes, $translations){ |
|
96 | + return static::unguarded(function() use ($locale, $model, $attributes, $translations){ |
|
97 | 97 | return $model->createInLocale($locale, $attributes, $translations); |
98 | 98 | }); |
99 | 99 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function forceSaveTranslations(array $translations) |
147 | 147 | { |
148 | - return static::unguarded(function () use ($translations){ |
|
148 | + return static::unguarded(function() use ($translations){ |
|
149 | 149 | return $this->saveTranslations($translations); |
150 | 150 | }); |
151 | 151 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function forceSaveTranslation($locale, array $attributes) |
171 | 171 | { |
172 | - return static::unguarded(function () use ($locale, $attributes){ |
|
172 | + return static::unguarded(function() use ($locale, $attributes){ |
|
173 | 173 | return $this->saveTranslation($locale, $attributes); |
174 | 174 | }); |
175 | 175 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | { |
196 | 196 | if (property_exists($this, 'translatable')) { |
197 | 197 | $attributes = $this->translatable; |
198 | - }else { |
|
198 | + } else { |
|
199 | 199 | $attributes = $this->getTranslatableAttributesFromSchema(); |
200 | 200 | } |
201 | 201 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function translatableAttributes() |
302 | 302 | { |
303 | - if(!isset(static::$i18nAttributes[$this->getTable()])) { |
|
303 | + if (!isset(static::$i18nAttributes[$this->getTable()])) { |
|
304 | 304 | return []; |
305 | 305 | } |
306 | 306 |
@@ -195,7 +195,7 @@ |
||
195 | 195 | { |
196 | 196 | if (property_exists($this, 'translatable')) { |
197 | 197 | $attributes = $this->translatable; |
198 | - }else { |
|
198 | + } else { |
|
199 | 199 | $attributes = $this->getTranslatableAttributesFromSchema(); |
200 | 200 | } |
201 | 201 |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected function qualifyColumns($columns) |
69 | 69 | { |
70 | - foreach($columns as &$column) { |
|
71 | - if(!in_array($column, $this->model->translatableAttributes())) { |
|
70 | + foreach ($columns as &$column) { |
|
71 | + if (!in_array($column, $this->model->translatableAttributes())) { |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $primary = $this->qualifyTranslationColumn($column); |
76 | 76 | $fallback = $this->qualifyTranslationColumn($column, true); |
77 | 77 | |
78 | - if($this->model->shouldFallback()) { |
|
78 | + if ($this->model->shouldFallback()) { |
|
79 | 79 | $column = new Expression($this->compileIfNull($primary, $fallback, $column)); |
80 | 80 | } else { |
81 | 81 | $column = $primary; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | // Then we need to check if we are dealing with a translated column and defer |
109 | 109 | // to the "whereTranslated" clause in that case. That way the user doesn't |
110 | 110 | // need to worry about translated columns and let us handle the details. |
111 | - if(in_array($column, $this->model->translatableAttributes())) { |
|
111 | + if (in_array($column, $this->model->translatableAttributes())) { |
|
112 | 112 | return $this->whereTranslated($column, $operator, $value, $boolean); |
113 | 113 | } |
114 | 114 | |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | // If the given operator is not found in the list of valid operators we will |
157 | 157 | // assume that the developer is just short-cutting the '=' operators and |
158 | 158 | // we will set the operators to '=' and set the values appropriately. |
159 | - if (! in_array(strtolower($operator), $this->operators, true)) { |
|
159 | + if (!in_array(strtolower($operator), $this->operators, true)) { |
|
160 | 160 | list($value, $operator) = [$operator, '=']; |
161 | 161 | } |
162 | 162 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public function orderBy($column, $direction = 'asc') |
220 | 220 | { |
221 | - if(in_array($column, $this->model->translatableAttributes())) { |
|
221 | + if (in_array($column, $this->model->translatableAttributes())) { |
|
222 | 222 | return $this->orderByTranslated($column, $direction); |
223 | 223 | } |
224 | 224 | |
@@ -256,13 +256,12 @@ discard block |
||
256 | 256 | $alias = $this->model->getI18nTable(); |
257 | 257 | $fallback = $fallback ? '_fallback' : ''; |
258 | 258 | |
259 | - if(Str::contains($column, '.')) { |
|
259 | + if (Str::contains($column, '.')) { |
|
260 | 260 | list($table, $field) = explode('.', $column); |
261 | 261 | $suffix = $this->model->getTranslationTableSuffix(); |
262 | 262 | |
263 | 263 | return Str::endsWith($alias, $suffix) ? |
264 | - "{$table}{$fallback}.{$field}" : |
|
265 | - "{$table}{$suffix}{$fallback}.{$field}"; |
|
264 | + "{$table}{$fallback}.{$field}" : "{$table}{$suffix}{$fallback}.{$field}"; |
|
266 | 265 | } |
267 | 266 | |
268 | 267 | return "{$alias}{$fallback}.{$column}"; |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | $this->i18nTable = $model->getI18nTable(); |
36 | 36 | $this->fallback = $model->getFallbackLocale(); |
37 | 37 | |
38 | - if(!Str::startsWith($this->table, 'laravel_reserved_')) { |
|
38 | + if (!Str::startsWith($this->table, 'laravel_reserved_')) { |
|
39 | 39 | $this->createJoin($builder, $model); |
40 | 40 | $this->createWhere($builder, $model); |
41 | 41 | $this->createSelect($builder, $model); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $clause = $this->getJoinClause($model, $this->locale, $this->i18nTable); |
54 | 54 | $builder->$joinType($this->i18nTable, $clause); |
55 | 55 | |
56 | - if($model->shouldFallback()) { |
|
56 | + if ($model->shouldFallback()) { |
|
57 | 57 | $clause = $this->getJoinClause($model, $this->fallback, $this->i18nTable . '_fallback'); |
58 | 58 | $builder->$joinType("{$this->i18nTable} as {$this->i18nTable}_fallback", $clause); |
59 | 59 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | protected function getJoinClause(Eloquent $model, $locale, $alias) |
80 | 80 | { |
81 | - return function (JoinClause $join) use ($model, $locale, $alias) { |
|
81 | + return function(JoinClause $join) use ($model, $locale, $alias) { |
|
82 | 82 | $primary = $model->getKeyName(); |
83 | 83 | $foreign = $model->getForeignKey(); |
84 | 84 | $langKey = $model->getLocaleKey(); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function createWhere(EloquentBuilder $builder, Eloquent $model) |
96 | 96 | { |
97 | - if($model->getOnlyTranslated() && $model->shouldFallback()) { |
|
97 | + if ($model->getOnlyTranslated() && $model->shouldFallback()) { |
|
98 | 98 | $key = $model->getForeignKey(); |
99 | 99 | $primary = "{$this->i18nTable}.{$key}"; |
100 | 100 | $fallback = "{$this->i18nTable}_fallback.{$key}"; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function createSelect(EloquentBuilder $builder, Eloquent $model) |
113 | 113 | { |
114 | - if($builder->getQuery()->columns) { |
|
114 | + if ($builder->getQuery()->columns) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function formatColumns(EloquentBuilder $builder, Eloquent $model) |
129 | 129 | { |
130 | - $map = function ($field) use ($builder, $model) { |
|
130 | + $map = function($field) use ($builder, $model) { |
|
131 | 131 | if (!$model->shouldFallback()) { |
132 | 132 | return "{$this->i18nTable}.{$field}"; |
133 | 133 | } |
@@ -158,53 +158,53 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function extend(EloquentBuilder $builder) |
160 | 160 | { |
161 | - $builder->macro('onlyTranslated', function (EloquentBuilder $builder, $locale = null) { |
|
161 | + $builder->macro('onlyTranslated', function(EloquentBuilder $builder, $locale = null) { |
|
162 | 162 | $builder->getModel()->setOnlyTranslated(true); |
163 | 163 | |
164 | - if($locale) { |
|
164 | + if ($locale) { |
|
165 | 165 | $builder->getModel()->setLocale($locale); |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $builder; |
169 | 169 | }); |
170 | 170 | |
171 | - $builder->macro('withUntranslated', function (EloquentBuilder $builder) { |
|
171 | + $builder->macro('withUntranslated', function(EloquentBuilder $builder) { |
|
172 | 172 | $builder->getModel()->setOnlyTranslated(false); |
173 | 173 | |
174 | 174 | return $builder; |
175 | 175 | }); |
176 | 176 | |
177 | - $builder->macro('withFallback', function (EloquentBuilder $builder, $fallbackLocale = null) { |
|
177 | + $builder->macro('withFallback', function(EloquentBuilder $builder, $fallbackLocale = null) { |
|
178 | 178 | $builder->getModel()->setWithFallback(true); |
179 | 179 | |
180 | - if($fallbackLocale) { |
|
180 | + if ($fallbackLocale) { |
|
181 | 181 | $builder->getModel()->setFallbackLocale($fallbackLocale); |
182 | 182 | } |
183 | 183 | |
184 | 184 | return $builder; |
185 | 185 | }); |
186 | 186 | |
187 | - $builder->macro('withoutFallback', function (EloquentBuilder $builder) { |
|
187 | + $builder->macro('withoutFallback', function(EloquentBuilder $builder) { |
|
188 | 188 | $builder->getModel()->setWithFallback(false); |
189 | 189 | |
190 | 190 | return $builder; |
191 | 191 | }); |
192 | 192 | |
193 | - $builder->macro('translateInto', function (EloquentBuilder $builder, $locale) { |
|
194 | - if($locale) { |
|
193 | + $builder->macro('translateInto', function(EloquentBuilder $builder, $locale) { |
|
194 | + if ($locale) { |
|
195 | 195 | $builder->getModel()->setLocale($locale); |
196 | 196 | } |
197 | 197 | |
198 | 198 | return $builder; |
199 | 199 | }); |
200 | 200 | |
201 | - $builder->macro('withoutTranslations', function (EloquentBuilder $builder) { |
|
201 | + $builder->macro('withoutTranslations', function(EloquentBuilder $builder) { |
|
202 | 202 | $builder->withoutGlobalScope(static::class); |
203 | 203 | |
204 | 204 | return $builder; |
205 | 205 | }); |
206 | 206 | |
207 | - $builder->macro('withAllTranslations', function (EloquentBuilder $builder) { |
|
207 | + $builder->macro('withAllTranslations', function(EloquentBuilder $builder) { |
|
208 | 208 | $builder->withoutGlobalScope(static::class) |
209 | 209 | ->with('translations'); |
210 | 210 |
@@ -103,7 +103,7 @@ |
||
103 | 103 | |
104 | 104 | protected static function checkIfSet($key1, $key2) |
105 | 105 | { |
106 | - if(empty(static::$config[$key1][$key2])) { |
|
106 | + if (empty(static::$config[$key1][$key2])) { |
|
107 | 107 | throw new Exception("Translatable is not configured correctly. Config for [$key1.$key2] is missing."); |
108 | 108 | } |
109 | 109 | } |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | |
23 | 23 | $ids = $modelKey ? [$modelKey] : $this->pluck($modelKeyName)->all(); |
24 | 24 | |
25 | - if($values) { |
|
25 | + if ($values) { |
|
26 | 26 | $updated += $this->updateBase($values, $ids); |
27 | 27 | } |
28 | 28 | |
29 | - if($i18nValues) { |
|
29 | + if ($i18nValues) { |
|
30 | 30 | $updated += $this->updateI18n($i18nValues, $ids); |
31 | 31 | } |
32 | 32 | |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | list($values, $i18nValues) = $this->filterValues($values); |
75 | 75 | |
76 | - if($this->query->insert($values)) { |
|
76 | + if ($this->query->insert($values)) { |
|
77 | 77 | return $this->insertI18n($i18nValues, $values[$this->model->getKeyName()]); |
78 | 78 | } |
79 | 79 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | { |
90 | 90 | list($values, $i18nValues) = $this->filterValues($values); |
91 | 91 | |
92 | - if($id = $this->query->insertGetId($values, $sequence)) { |
|
93 | - if($this->insertI18n($i18nValues, $id)) { |
|
92 | + if ($id = $this->query->insertGetId($values, $sequence)) { |
|
93 | + if ($this->insertI18n($i18nValues, $id)) { |
|
94 | 94 | return $id; |
95 | 95 | } |
96 | 96 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | |
135 | 135 | $translatable = []; |
136 | 136 | |
137 | - foreach($attributes as $key) { |
|
138 | - if(array_key_exists($key, $values)) { |
|
137 | + foreach ($attributes as $key) { |
|
138 | + if (array_key_exists($key, $values)) { |
|
139 | 139 | $translatable[$key] = $values[$key]; |
140 | 140 | |
141 | 141 | unset($values[$key]); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function insertI18n(array $values, $key) |
154 | 154 | { |
155 | - if(count($values) == 0) { |
|
155 | + if (count($values) == 0) { |
|
156 | 156 | return true; |
157 | 157 | } |
158 | 158 | |
@@ -185,18 +185,18 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function updateI18n(array $values, array $ids) |
187 | 187 | { |
188 | - if(count($values) == 0) { |
|
188 | + if (count($values) == 0) { |
|
189 | 189 | return true; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $updated = 0; |
193 | 193 | |
194 | - foreach($ids as $id) { |
|
194 | + foreach ($ids as $id) { |
|
195 | 195 | $query = $this->i18nQuery() |
196 | 196 | ->whereOriginal($this->model->getForeignKey(), $id) |
197 | 197 | ->whereOriginal($this->model->getLocaleKey(), $this->model->getLocale()); |
198 | 198 | |
199 | - if($query->exists()) { |
|
199 | + if ($query->exists()) { |
|
200 | 200 | unset($values[$this->model->getLocaleKey()]); |
201 | 201 | $updated += $query->update($values); |
202 | 202 | } else { |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |----------------------------------------------------------- |
7 | 7 | | Database schema conventions |
8 | 8 | |----------------------------------------------------------- |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | ], |
19 | 19 | |
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | |----------------------------------------------------------- |
23 | 23 | | Default query behavior |
24 | 24 | |----------------------------------------------------------- |