Passed
Push — master ( 868a85...47fe80 )
by Morten Poul
03:20
created

Translation::scopeForLang()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Signifly\Translator\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphTo;
8
use Signifly\Translator\Contracts\Translation as TranslationContract;
9
10
class Translation extends Model implements TranslationContract
11
{
12
    /**
13
     * The attributes that are mass assignable.
14
     *
15
     * @var array
16
     */
17
    protected $fillable = [
18
        'language_code',
19
        'key',
20
        'value',
21
    ];
22
23
    public function __construct(array $attributes = [])
24
    {
25
        if (! isset($this->table)) {
26
            $this->setTable(config('translator.table_name'));
27
        }
28
29
        parent::__construct($attributes);
30
    }
31
32
    /**
33
     * The associated translatable relation.
34
     *
35
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
36
     */
37
    public function translatable(): MorphTo
38
    {
39
        return $this->morphTo();
40
    }
41
42
    /**
43
     * Scope a query to only include translations for a given language.
44
     *
45
     * @param  \Illuminate\Database\Eloquent\Builder $query
46
     * @param  string  $langCode
47
     * @return \Illuminate\Database\Eloquent\Builder
48
     */
49
    public function scopeForLang(Builder $query, string $langCode): Builder
50
    {
51
        return $query->where('language_code', $langCode);
52
    }
53
}
54