Completed
Push — master ( f67f4f...77dcfd )
by Curtis
40s queued 12s
created

Language::scopeExtra()   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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Models\enso\Localisation;
4
5
use Illuminate\Database\Eloquent\Model;
6
use LaravelEnso\Helpers\App\Contracts\Activatable;
7
use LaravelEnso\Helpers\App\Traits\ActiveState;
8
use LaravelEnso\Tables\App\Traits\TableCache;
9
/**
10
 * @property int $id
11
 * @property string $name
12
 * @property string $display_name
13
 * @property string $flag
14
 * @property boolean $is_rtl
15
 * @property boolean $is_active
16
 * @property string $created_at
17
 * @property string $updated_at
18
 */
19
class Language extends Model implements Activatable
20
{
21
    /**
22
     * The table associated with the model.
23
     * 
24
     * @var string
25
     */
26
    protected $table = 'languages';
27
28
    use ActiveState, TableCache;
29
30
    public const FlagClassPrefix = 'flag-icon flag-icon-';
31
32
    protected $fillable = ['name', 'display_name', 'flag', 'is_rtl', 'is_active'];
33
34
    protected $casts = ['is_rtl' => 'boolean', 'is_active' => 'boolean'];
35
36
    public function updateWithFlagSufix($attributes, string $sufix)
37
    {
38
        $this->fill($attributes);
39
40
        $this->flag = self::FlagClassPrefix.$sufix;
41
42
        $this->update();
43
    }
44
45
    public function storeWithFlagSufix($attributes, string $sufix)
46
    {
47
        $this->fill($attributes);
48
49
        $this->flag = self::FlagClassPrefix.$sufix;
50
51
        return tap($this)->save();
52
    }
53
54
    public function scopeExtra($query)
55
    {
56
        return $query->where('name', '<>', config('app.fallback_locale'));
57
    }
58
}
59