Conditions | 4 |
Paths | 3 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
36 | public function getTranslations($key): array |
||
37 | { |
||
38 | $this->guardAgainstUntranslatableAttribute($key); |
||
39 | $value = json_decode($this->getAttributes()[$key] ?? '' ?: '{}', true); |
||
40 | |||
41 | // Inject default translation if none supplied |
||
42 | if (! is_array($value)) { |
||
43 | $oldValue = $value; |
||
44 | |||
45 | if ($this->hasSetMutator($key)) { |
||
46 | $method = 'set'.Str::studly($key).'Attribute'; |
||
47 | $value = $this->{$method}($value); |
||
48 | } |
||
49 | |||
50 | $value = [$locale = app()->getLocale() => $value]; |
||
51 | |||
52 | $this->attributes[$key] = $this->asJson($value); |
||
53 | event(new TranslationHasBeenSet($this, $key, $locale, $oldValue, $value)); |
||
54 | } |
||
55 | |||
56 | return $value; |
||
57 | } |
||
58 | } |
||
59 |