Completed
Push — develop ( 3ba432...36e0ad )
by Abdelrahman
01:06
created

HasTranslations::getAttributeValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Support\Traits;
6
7
use Spatie\Translatable\HasTranslations as BaseHasTranslations;
8
9
trait HasTranslations
10
{
11
    use BaseHasTranslations;
12
13
    /**
14
     * @param string $key
15
     *
16
     * @return mixed
17
     */
18
    public function getAttributeValue($key)
19
    {
20
        if (! $this->isTranslatableAttribute($key)) {
21
            return parent::getAttributeValue($key);
22
        }
23
24
        return $this->getTranslation($key, config('app.locale')) ?: array_first($this->getTranslations($key));
25
    }
26
}
27