Test Setup Failed
Pull Request — master (#575)
by Tom
280:26 queued 278:32
created

Translatable::getRelationKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Dimsav\Translatable;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Query\JoinClause;
8
use Illuminate\Database\Eloquent\Relations\Relation;
9
use Illuminate\Database\Query\Builder as QueryBuilder;
10
use Dimsav\Translatable\Exception\LocalesNotDefinedException;
11
12
trait Translatable
13
{
14
    protected static $autoloadTranslations = null;
15
16
    protected $defaultLocale;
17
18
    /**
19
     * Alias for getTranslation().
20
     *
21
     * @param string|null $locale
22
     * @param bool        $withFallback
23
     *
24
     * @return \Illuminate\Database\Eloquent\Model|null
25
     */
26 52
    public function translate($locale = null, $withFallback = false)
27
    {
28 52
        return $this->getTranslation($locale, $withFallback);
29
    }
30
31
    /**
32
     * Alias for getTranslation().
33
     *
34
     * @param string $locale
35
     *
36
     * @return \Illuminate\Database\Eloquent\Model|null
37
     */
38 4
    public function translateOrDefault($locale = null)
39
    {
40 4
        return $this->getTranslation($locale, true);
41
    }
42
43
    /**
44
     * Alias for getTranslationOrNew().
45
     *
46
     * @param string $locale
47
     *
48
     * @return \Illuminate\Database\Eloquent\Model|null
49
     */
50 4
    public function translateOrNew($locale = null)
51
    {
52 4
        return $this->getTranslationOrNew($locale);
53
    }
54
55
    /**
56
     * @param string|null $locale
57
     * @param bool        $withFallback
58
     *
59
     * @return \Illuminate\Database\Eloquent\Model|null
60
     */
61 248
    public function getTranslation($locale = null, $withFallback = null)
62
    {
63 248
        $configFallbackLocale = $this->getFallbackLocale();
64 248
        $locale = $locale ?: $this->locale();
65 248
        $withFallback = $withFallback === null ? $this->useFallback() : $withFallback;
66 248
        $fallbackLocale = $this->getFallbackLocale($locale);
67
68 248
        if ($translation = $this->getTranslationByLocaleKey($locale)) {
69 140
            return $translation;
70
        }
71 168
        if ($withFallback && $fallbackLocale) {
72 28
            if ($translation = $this->getTranslationByLocaleKey($fallbackLocale)) {
73 16
                return $translation;
74
            }
75 12
            if ($fallbackLocale !== $configFallbackLocale && $translation = $this->getTranslationByLocaleKey($configFallbackLocale)) {
76 8
                return $translation;
77
            }
78
        }
79
80 164
        return null;
81
    }
82
83
    /**
84
     * @param string|null $locale
85
     *
86
     * @return bool
87
     */
88 12
    public function hasTranslation($locale = null)
89
    {
90 12
        $locale = $locale ?: $this->locale();
91
92 12
        foreach ($this->translations as $translation) {
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
93 4
            if ($translation->getAttribute($this->getLocaleKey()) == $locale) {
94 4
                return true;
95
            }
96
        }
97
98 12
        return false;
99
    }
100
101
    /**
102
     * @return string
103
     */
104 312
    public function getTranslationModelName()
105
    {
106 312
        return $this->translationModel ?: $this->getTranslationModelNameDefault();
0 ignored issues
show
Bug introduced by
The property translationModel does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
107
    }
108
109
    /**
110
     * @return string
111
     */
112 304
    public function getTranslationModelNameDefault()
113
    {
114 304
        $modelName = get_class($this);
115
116 304
        if ($namespace = $this->getTranslationModelNamespace()) {
117 4
            $modelName = $namespace.'\\'.class_basename(get_class($this));
118
        }
119
120 304
        return $modelName.config('translatable.translation_suffix', 'Translation');
121
    }
122
123
    /**
124
     * @return string|null
125
     */
126 304
    public function getTranslationModelNamespace()
127
    {
128 304
        return config('translatable.translation_model_namespace');
129
    }
130
131
    /**
132
     * @return string
133
     */
134 312
    public function getRelationKey()
135
    {
136 312
        if ($this->translationForeignKey) {
137 24
            return $this->translationForeignKey;
0 ignored issues
show
Bug introduced by
The property translationForeignKey does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
138
        }
139
140 292
        return $this->getForeignKey();
0 ignored issues
show
Bug introduced by
It seems like getForeignKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
141
    }
142
143
    /**
144
     * @return string
145
     */
146 292
    public function getLocaleKey()
147
    {
148 292
        return $this->localeKey ?: config('translatable.locale_key', 'locale');
0 ignored issues
show
Bug introduced by
The property localeKey does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
149
    }
150
151
    /**
152
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
153
     */
154 292
    public function translations()
155
    {
156 292
        return $this->hasMany($this->getTranslationModelName(), $this->getRelationKey());
0 ignored issues
show
Bug introduced by
It seems like hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
157
    }
158
159
    /**
160
     * @return bool
161
     */
162 12
    private function usePropertyFallback()
163
    {
164 12
        return $this->useFallback() && config('translatable.use_property_fallback', false);
165
    }
166
167
    /**
168
     * Returns the attribute value from fallback translation if value of attribute
169
     * is empty and the property fallback is enabled in the configuration.
170
     * in model.
171
     * @param $locale
172
     * @param $attribute
173
     * @return mixed
174
     */
175 92
    private function getAttributeOrFallback($locale, $attribute)
176
    {
177 92
        $translation = $this->getTranslation($locale);
178
179
        if (
180
            (
181 92
                ! $translation instanceof Model ||
182 92
                empty($translation->$attribute)
183
            ) &&
184 92
            $this->usePropertyFallback()
185
        ) {
186 8
            $translation = $this->getTranslation($this->getFallbackLocale(), false);
187
        }
188
189 92
        if ($translation instanceof Model) {
190 88
            return $translation->$attribute;
191
        }
192
193 8
        return null;
194
    }
195
196
    /**
197
     * @param string $key
198
     *
199
     * @return mixed
200
     */
201 388
    public function getAttribute($key)
202
    {
203 388
        [$attribute, $locale] = $this->getAttributeAndLocale($key);
0 ignored issues
show
Bug introduced by
The variable $attribute does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $locale does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
204
205 388
        if ($this->isTranslationAttribute($attribute)) {
206 72
            if ($this->getTranslation($locale) === null) {
207 12
                return $this->getAttributeValue($attribute);
0 ignored issues
show
Bug introduced by
The method getAttributeValue() does not exist on Dimsav\Translatable\Translatable. Did you maybe mean getAttribute()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
208
            }
209
210
            // If the given $attribute has a mutator, we push it to $attributes and then call getAttributeValue
211
            // on it. This way, we can use Eloquent's checking for Mutation, type casting, and
212
            // Date fields.
213 60
            if ($this->hasGetMutator($attribute)) {
0 ignored issues
show
Bug introduced by
It seems like hasGetMutator() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
214 4
                $this->attributes[$attribute] = $this->getAttributeOrFallback($locale, $attribute);
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
215
216 4
                return $this->getAttributeValue($attribute);
0 ignored issues
show
Bug introduced by
The method getAttributeValue() does not exist on Dimsav\Translatable\Translatable. Did you maybe mean getAttribute()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
217
            }
218
219 56
            return $this->getAttributeOrFallback($locale, $attribute);
220
        }
221
222 388
        return parent::getAttribute($key);
223
    }
224
225
    /**
226
     * @param string $key
227
     * @param mixed  $value
228
     *
229
     * @return $this
230
     */
231 388
    public function setAttribute($key, $value)
232
    {
233 388
        [$attribute, $locale] = $this->getAttributeAndLocale($key);
0 ignored issues
show
Bug introduced by
The variable $attribute does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $locale does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
234
235 388
        if ($this->isTranslationAttribute($attribute)) {
236 40
            $this->getTranslationOrNew($locale)->$attribute = $value;
237
        } else {
238 388
            return parent::setAttribute($key, $value);
239
        }
240
241 40
        return $this;
242
    }
243
244
    /**
245
     * @param array $options
246
     *
247
     * @return bool
248
     */
249 388
    public function save(array $options = [])
250
    {
251 388
        if ($this->exists && ! $this->isDirty()) {
0 ignored issues
show
Bug introduced by
The property exists does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like isDirty() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
252
            // If $this->exists and not dirty, parent::save() skips saving and returns
253
            // false. So we have to save the translations
254 24
            if ($this->fireModelEvent('saving') === false) {
0 ignored issues
show
Bug introduced by
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
255
                return false;
256
            }
257
258 24
            if ($saved = $this->saveTranslations()) {
259 24
                $this->fireModelEvent('saved', false);
0 ignored issues
show
Bug introduced by
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
260 24
                $this->fireModelEvent('updated', false);
0 ignored issues
show
Bug introduced by
It seems like fireModelEvent() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
261
            }
262
263 24
            return $saved;
264
        }
265
266
        // We save the translations only if the instance is saved in the database.
267 388
        if (parent::save($options)) {
268 388
            return $this->saveTranslations();
269
        }
270
271 8
        return false;
272
    }
273
274
    /**
275
     * @param string $locale
276
     *
277
     * @return \Illuminate\Database\Eloquent\Model
278
     */
279 140
    protected function getTranslationOrNew($locale = null)
280
    {
281 140
        $locale = $locale ?: $this->locale();
282
283 140
        if (($translation = $this->getTranslation($locale, false)) === null) {
284 124
            $translation = $this->getNewTranslation($locale);
285
        }
286
287 140
        return $translation;
288
    }
289
290
    /**
291
     * @param array $attributes
292
     *
293
     * @throws \Illuminate\Database\Eloquent\MassAssignmentException
294
     * @return $this
295
     */
296 388
    public function fill(array $attributes)
297
    {
298 388
        foreach ($attributes as $key => $values) {
299 112
            if ($this->isKeyALocale($key)) {
300 48
                $this->getTranslationOrNew($key)->fill($values);
301 40
                unset($attributes[$key]);
302
            } else {
303 100
                [$attribute, $locale] = $this->getAttributeAndLocale($key);
0 ignored issues
show
Bug introduced by
The variable $attribute does not exist. Did you mean $attributes?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
Bug introduced by
The variable $locale does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
304 100
                if ($this->isTranslationAttribute($attribute) and $this->isKeyALocale($locale)) {
0 ignored issues
show
Bug introduced by
The variable $attribute does not exist. Did you mean $attributes?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
305 48
                    $this->getTranslationOrNew($locale)->fill([$attribute => $values]);
0 ignored issues
show
Bug introduced by
The variable $attribute does not exist. Did you mean $attributes?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
306 48
                    unset($attributes[$key]);
307
                }
308
            }
309
        }
310
311 388
        return parent::fill($attributes);
312
    }
313
314
    /**
315
     * @param string $key
316
     */
317 248
    private function getTranslationByLocaleKey($key)
318
    {
319 248
        foreach ($this->translations as $translation) {
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
320 196
            if ($translation->getAttribute($this->getLocaleKey()) == $key) {
321 164
                return $translation;
322
            }
323
        }
324
325 168
        return null;
326
    }
327
328
    /**
329
     * @param null $locale
330
     *
331
     * @return string
332
     */
333 252
    private function getFallbackLocale($locale = null)
334
    {
335 252
        if ($locale && $this->isLocaleCountryBased($locale)) {
336 28
            if ($fallback = $this->getLanguageFromCountryBasedLocale($locale)) {
337 28
                return $fallback;
338
            }
339
        }
340
341 252
        return config('translatable.fallback_locale');
342
    }
343
344
    /**
345
     * @param $locale
346
     *
347
     * @return bool
348
     */
349 248
    private function isLocaleCountryBased($locale)
350
    {
351 248
        return strpos($locale, $this->getLocaleSeparator()) !== false;
352
    }
353
354
    /**
355
     * @param $locale
356
     *
357
     * @return string
358
     */
359 28
    private function getLanguageFromCountryBasedLocale($locale)
360
    {
361 28
        $parts = explode($this->getLocaleSeparator(), $locale);
362
363 28
        return array_get($parts, 0);
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated with message: Arr::get() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
364
    }
365
366
    /**
367
     * @return bool|null
368
     */
369 144
    private function useFallback()
370
    {
371 144
        if (isset($this->useTranslationFallback) && $this->useTranslationFallback !== null) {
372 12
            return $this->useTranslationFallback;
0 ignored issues
show
Bug introduced by
The property useTranslationFallback does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
373
        }
374
375 132
        return config('translatable.use_fallback');
376
    }
377
378
    /**
379
     * @param string $key
380
     *
381
     * @return bool
382
     */
383 388
    public function isTranslationAttribute($key)
384
    {
385 388
        return in_array($key, $this->translatedAttributes);
0 ignored issues
show
Bug introduced by
The property translatedAttributes does not seem to exist. Did you mean attributes?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
386
    }
387
388
    /**
389
     * @param string $key
390
     *
391
     * @throws \Dimsav\Translatable\Exception\LocalesNotDefinedException
392
     * @return bool
393
     */
394 112
    protected function isKeyALocale($key)
395
    {
396 112
        $locales = $this->getLocales();
397
398 108
        return in_array($key, $locales);
399
    }
400
401
    /**
402
     * @throws \Dimsav\Translatable\Exception\LocalesNotDefinedException
403
     * @return array
404
     */
405 112
    protected function getLocales()
406
    {
407 112
        $localesConfig = (array) config('translatable.locales');
408
409 112
        if (empty($localesConfig)) {
410 4
            throw new LocalesNotDefinedException('Please make sure you have run "php artisan config:publish dimsav/laravel-translatable" '.
411 4
                ' and that the locales configuration is defined.');
412
        }
413
414 108
        $locales = [];
415 108
        foreach ($localesConfig as $key => $locale) {
416 108
            if (is_array($locale)) {
417 20
                $locales[] = $key;
418 20
                foreach ($locale as $countryLocale) {
419 20
                    $locales[] = $key.$this->getLocaleSeparator().$countryLocale;
420
                }
421
            } else {
422 100
                $locales[] = $locale;
423
            }
424
        }
425
426 108
        return $locales;
427
    }
428
429
    /**
430
     * @return string
431
     */
432 248
    protected function getLocaleSeparator()
433
    {
434 248
        return config('translatable.locale_separator', '-');
435
    }
436
437
    /**
438
     * @return bool
439
     */
440 388
    protected function saveTranslations()
441
    {
442 388
        $saved = true;
443
444 388
        if (! $this->relationLoaded('translations')) {
0 ignored issues
show
Bug introduced by
It seems like relationLoaded() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
445 388
            return $saved;
446
        }
447
448 100
        foreach ($this->translations as $translation) {
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
449 100
            if ($saved && $this->isTranslationDirty($translation)) {
450 100
                if (! empty($connectionName = $this->getConnectionName())) {
0 ignored issues
show
Bug introduced by
It seems like getConnectionName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
451 100
                    $translation->setConnection($connectionName);
452
                }
453
454 100
                $translation->setAttribute($this->getRelationKey(), $this->getKey());
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
455 100
                $saved = $translation->save();
456
            }
457
        }
458
459 96
        return $saved;
460
    }
461
462
    /**
463
     * @param array
464
     *
465
     * @return \Illuminate\Database\Eloquent\Model
466
     */
467 4
    public function replicateWithTranslations(array $except = null)
468
    {
469 4
        $newInstance = parent::replicate($except);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (replicate() instead of replicateWithTranslations()). Are you sure this is correct? If so, you might want to change this to $this->replicate().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
470
471 4
        unset($newInstance->translations);
472 4
        foreach ($this->translations as $translation) {
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
473 4
            $newTranslation = $translation->replicate();
474 4
            $newInstance->translations->add($newTranslation);
475
        }
476
477 4
        return  $newInstance;
478
    }
479
480
    /**
481
     * @param \Illuminate\Database\Eloquent\Model $translation
482
     *
483
     * @return bool
484
     */
485 100
    protected function isTranslationDirty(Model $translation)
486
    {
487 100
        $dirtyAttributes = $translation->getDirty();
488 100
        unset($dirtyAttributes[$this->getLocaleKey()]);
489
490 100
        return count($dirtyAttributes) > 0;
491
    }
492
493
    /**
494
     * @param string $locale
495
     *
496
     * @return \Illuminate\Database\Eloquent\Model
497
     */
498 128
    public function getNewTranslation($locale)
499
    {
500 128
        $modelName = $this->getTranslationModelName();
501 128
        $translation = new $modelName();
502 128
        $translation->setAttribute($this->getLocaleKey(), $locale);
503 128
        $this->translations->add($translation);
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
504
505 128
        return $translation;
506
    }
507
508
    /**
509
     * @param $key
510
     *
511
     * @return bool
512
     */
513 148
    public function __isset($key)
514
    {
515 148
        return $this->isTranslationAttribute($key) || parent::__isset($key);
516
    }
517
518
    /**
519
     * @param \Illuminate\Database\Eloquent\Builder $query
520
     * @param string                                $locale
521
     *
522
     * @return \Illuminate\Database\Eloquent\Builder|static
523
     */
524 8
    public function scopeTranslatedIn(Builder $query, $locale = null)
525
    {
526 8
        $locale = $locale ?: $this->locale();
527
528
        return $query->whereHas('translations', function (Builder $q) use ($locale) {
529 8
            $q->where($this->getLocaleKey(), '=', $locale);
530 8
        });
531
    }
532
533
    /**
534
     * @param \Illuminate\Database\Eloquent\Builder $query
535
     * @param string                                $locale
536
     *
537
     * @return \Illuminate\Database\Eloquent\Builder|static
538
     */
539 8
    public function scopeNotTranslatedIn(Builder $query, $locale = null)
540
    {
541 8
        $locale = $locale ?: $this->locale();
542
543
        return $query->whereDoesntHave('translations', function (Builder $q) use ($locale) {
544 8
            $q->where($this->getLocaleKey(), '=', $locale);
545 8
        });
546
    }
547
548
    /**
549
     * @param \Illuminate\Database\Eloquent\Builder $query
550
     *
551
     * @return \Illuminate\Database\Eloquent\Builder|static
552
     */
553 4
    public function scopeTranslated(Builder $query)
554
    {
555 4
        return $query->has('translations');
556
    }
557
558
    /**
559
     * Adds scope to get a list of translated attributes, using the current locale.
560
     * Example usage: Country::listsTranslations('name')->get()->toArray()
561
     * Will return an array with items:
562
     *  [
563
     *      'id' => '1',                // The id of country
564
     *      'name' => 'Griechenland'    // The translated name
565
     *  ].
566
     *
567
     * @param \Illuminate\Database\Eloquent\Builder $query
568
     * @param string                                $translationField
569
     */
570 12
    public function scopeListsTranslations(Builder $query, $translationField)
571
    {
572 12
        $withFallback = $this->useFallback();
573 12
        $translationTable = $this->getTranslationsTable();
574 12
        $localeKey = $this->getLocaleKey();
575
576
        $query
0 ignored issues
show
Bug introduced by
The method select() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean createSelectWithConstraint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
577 12
            ->select($this->getTable().'.'.$this->getKeyName(), $translationTable.'.'.$translationField)
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
578 12
            ->leftJoin($translationTable, $translationTable.'.'.$this->getRelationKey(), '=', $this->getTable().'.'.$this->getKeyName())
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
Bug introduced by
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
579 12
            ->where($translationTable.'.'.$localeKey, $this->locale());
580 12
        if ($withFallback) {
581
            $query->orWhere(function (Builder $q) use ($translationTable, $localeKey) {
582 4
                $q->where($translationTable.'.'.$localeKey, $this->getFallbackLocale())
583
                  ->whereNotIn($translationTable.'.'.$this->getRelationKey(), function (QueryBuilder $q) use (
584 4
                      $translationTable,
585 4
                      $localeKey
586
                  ) {
587 4
                      $q->select($translationTable.'.'.$this->getRelationKey())
588 4
                        ->from($translationTable)
589 4
                        ->where($translationTable.'.'.$localeKey, $this->locale());
590 4
                  });
591 4
            });
592
        }
593 12
    }
594
595
    /**
596
     * This scope eager loads the translations for the default and the fallback locale only.
597
     * We can use this as a shortcut to improve performance in our application.
598
     *
599
     * @param Builder $query
600
     */
601 12
    public function scopeWithTranslation(Builder $query)
602
    {
603 12
        $query->with([
604
            'translations' => function (Relation $query) {
605 12
                if ($this->useFallback()) {
606 8
                    $locale = $this->locale();
607 8
                    $countryFallbackLocale = $this->getFallbackLocale($locale); // e.g. de-DE => de
608 8
                    $locales = array_unique([$locale, $countryFallbackLocale, $this->getFallbackLocale()]);
609
610 8
                    return $query->whereIn($this->getTranslationsTable().'.'.$this->getLocaleKey(), $locales);
0 ignored issues
show
Bug introduced by
The method whereIn() does not exist on Illuminate\Database\Eloquent\Relations\Relation. Did you maybe mean whereInMethod()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
611
                }
612
613 4
                return $query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $this->locale());
614 12
            },
615
        ]);
616 12
    }
617
618
    /**
619
     * This scope filters results by checking the translation fields.
620
     *
621
     * @param \Illuminate\Database\Eloquent\Builder $query
622
     * @param string                                $key
623
     * @param string                                $value
624
     * @param string                                $locale
625
     *
626
     * @return \Illuminate\Database\Eloquent\Builder|static
627
     */
628 12
    public function scopeWhereTranslation(Builder $query, $key, $value, $locale = null)
629
    {
630
        return $query->whereHas('translations', function (Builder $query) use ($key, $value, $locale) {
631 12
            $query->where($this->getTranslationsTable().'.'.$key, $value);
632 12
            if ($locale) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $locale of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
633 4
                $query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $locale);
634
            }
635 12
        });
636
    }
637
638
    /**
639
     * This scope filters results by checking the translation fields.
640
     *
641
     * @param \Illuminate\Database\Eloquent\Builder $query
642
     * @param string                                $key
643
     * @param string                                $value
644
     * @param string                                $locale
645
     *
646
     * @return \Illuminate\Database\Eloquent\Builder|static
647
     */
648 4
    public function scopeOrWhereTranslation(Builder $query, $key, $value, $locale = null)
649
    {
650
        return $query->orWhereHas('translations', function (Builder $query) use ($key, $value, $locale) {
651 4
            $query->where($this->getTranslationsTable().'.'.$key, $value);
652 4
            if ($locale) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $locale of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
653
                $query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), $locale);
654
            }
655 4
        });
656
    }
657
658
    /**
659
     * This scope filters results by checking the translation fields.
660
     *
661
     * @param \Illuminate\Database\Eloquent\Builder $query
662
     * @param string                                $key
663
     * @param string                                $value
664
     * @param string                                $locale
665
     *
666
     * @return \Illuminate\Database\Eloquent\Builder|static
667
     */
668 12
    public function scopeWhereTranslationLike(Builder $query, $key, $value, $locale = null)
669
    {
670
        return $query->whereHas('translations', function (Builder $query) use ($key, $value, $locale) {
671 12
            $query->where($this->getTranslationsTable().'.'.$key, 'LIKE', $value);
672 12
            if ($locale) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $locale of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
673 4
                $query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), 'LIKE', $locale);
674
            }
675 12
        });
676
    }
677
678
    /**
679
     * This scope filters results by checking the translation fields.
680
     *
681
     * @param \Illuminate\Database\Eloquent\Builder $query
682
     * @param string                                $key
683
     * @param string                                $value
684
     * @param string                                $locale
685
     *
686
     * @return \Illuminate\Database\Eloquent\Builder|static
687
     */
688 4
    public function scopeOrWhereTranslationLike(Builder $query, $key, $value, $locale = null)
689
    {
690
        return $query->orWhereHas('translations', function (Builder $query) use ($key, $value, $locale) {
691 4
            $query->where($this->getTranslationsTable().'.'.$key, 'LIKE', $value);
692 4
            if ($locale) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $locale of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
693
                $query->where($this->getTranslationsTable().'.'.$this->getLocaleKey(), 'LIKE', $locale);
694
            }
695 4
        });
696
    }
697
698
    /**
699
     * This scope sorts results by the given translation field.
700
     *
701
     * @param \Illuminate\Database\Eloquent\Builder $query
702
     * @param string                                $key
703
     * @param string                                $sortmethod
704
     *
705
     * @return \Illuminate\Database\Eloquent\Builder|static
706
     */
707 8
    public function scopeOrderByTranslation(Builder $query, $key, $sortmethod = 'asc')
708
    {
709 8
        $translationTable = $this->getTranslationsTable();
710 8
        $localeKey = $this->getLocaleKey();
711 8
        $table = $this->getTable();
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
712 8
        $keyName = $this->getKeyName();
0 ignored issues
show
Bug introduced by
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
713
714
        return $query
715
            ->join($translationTable, function (JoinClause $join) use ($translationTable, $localeKey, $table, $keyName) {
716
                $join
717 8
                    ->on($translationTable.'.'.$this->getRelationKey(), '=', $table.'.'.$keyName)
718 8
                    ->where($translationTable.'.'.$localeKey, $this->locale());
719 8
            })
720 8
            ->orderBy($translationTable.'.'.$key, $sortmethod)
721 8
            ->select($table.'.*')
722 8
            ->with('translations');
723
    }
724
725
    /**
726
     * @return array
727
     */
728 48
    public function attributesToArray()
729
    {
730 48
        $attributes = parent::attributesToArray();
731
732
        if (
733 48
            (! $this->relationLoaded('translations') && ! $this->toArrayAlwaysLoadsTranslations() && is_null(self::$autoloadTranslations))
0 ignored issues
show
Bug introduced by
It seems like relationLoaded() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
734 48
            || self::$autoloadTranslations === false
735
        ) {
736 16
            return $attributes;
737
        }
738
739 32
        $hiddenAttributes = $this->getHidden();
0 ignored issues
show
Bug introduced by
It seems like getHidden() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
740
741 32
        foreach ($this->translatedAttributes as $field) {
0 ignored issues
show
Bug introduced by
The property translatedAttributes does not seem to exist. Did you mean attributes?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
742 32
            if (in_array($field, $hiddenAttributes)) {
743 4
                continue;
744
            }
745
746 32
            $attributes[$field] = $this->getAttributeOrFallback(null, $field);
747
        }
748
749 32
        return $attributes;
750
    }
751
752
    /**
753
     * @return array
754
     */
755 4
    public function getTranslationsArray()
756
    {
757 4
        $translations = [];
758
759 4
        foreach ($this->translations as $translation) {
0 ignored issues
show
Bug introduced by
The property translations does not seem to exist. Did you mean autoloadTranslations?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
760 4
            foreach ($this->translatedAttributes as $attr) {
0 ignored issues
show
Bug introduced by
The property translatedAttributes does not seem to exist. Did you mean attributes?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
761 4
                $translations[$translation->{$this->getLocaleKey()}][$attr] = $translation->{$attr};
762
            }
763
        }
764
765 4
        return $translations;
766
    }
767
768
    /**
769
     * @return string
770
     */
771 56
    private function getTranslationsTable()
772
    {
773 56
        return app()->make($this->getTranslationModelName())->getTable();
774
    }
775
776
    /**
777
     * @return string
778
     */
779 388
    protected function locale()
780
    {
781 388
        if ($this->defaultLocale) {
782 4
            return $this->defaultLocale;
783
        }
784
785 388
        return config('translatable.locale')
786 388
            ?: app()->make('translator')->getLocale();
787
    }
788
789
    /**
790
     * Set the default locale on the model.
791
     *
792
     * @param $locale
793
     *
794
     * @return $this
795
     */
796 4
    public function setDefaultLocale($locale)
797
    {
798 4
        $this->defaultLocale = $locale;
799
800 4
        return $this;
801
    }
802
803
    /**
804
     * Get the default locale on the model.
805
     *
806
     * @return mixed
807
     */
808
    public function getDefaultLocale()
809
    {
810
        return $this->defaultLocale;
811
    }
812
813
    /**
814
     * Deletes all translations for this model.
815
     *
816
     * @param string|array|null $locales The locales to be deleted (array or single string)
817
     *                                   (e.g., ["en", "de"] would remove these translations).
818
     */
819 12
    public function deleteTranslations($locales = null)
820
    {
821 12
        if ($locales === null) {
822 4
            $translations = $this->translations()->get();
823
        } else {
824 8
            $locales = (array) $locales;
825 8
            $translations = $this->translations()->whereIn($this->getLocaleKey(), $locales)->get();
0 ignored issues
show
Bug introduced by
The method whereIn() does not exist on Illuminate\Database\Eloquent\Relations\HasMany. Did you maybe mean whereInMethod()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
826
        }
827 12
        foreach ($translations as $translation) {
828 8
            $translation->delete();
829
        }
830
831
        // we need to manually "reload" the collection built from the relationship
832
        // otherwise $this->translations()->get() would NOT be the same as $this->translations
833 12
        $this->load('translations');
0 ignored issues
show
Bug introduced by
It seems like load() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
834 12
    }
835
836
    /**
837
     * @param $key
838
     *
839
     * @return array
840
     */
841 388
    private function getAttributeAndLocale($key)
842
    {
843 388
        if (str_contains($key, ':')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
844 44
            return explode(':', $key);
845
        }
846
847 388
        return [$key, $this->locale()];
848
    }
849
850
    /**
851
     * @return bool
852
     */
853 32
    private function toArrayAlwaysLoadsTranslations()
854
    {
855 32
        return config('translatable.to_array_always_loads_translations', true);
856
    }
857
858
    public static function enableAutoloadTranslations()
859
    {
860
        self::$autoloadTranslations = true;
861
    }
862
863 4
    public static function defaultAutoloadTranslations()
864
    {
865 4
        self::$autoloadTranslations = null;
866 4
    }
867
868 4
    public static function disableAutoloadTranslations()
869
    {
870 4
        self::$autoloadTranslations = false;
871 4
    }
872
}
873