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
|
|
|
|