|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PWWEB\Localisation\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Eloquent as Model; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
|
7
|
|
|
use PWWEB\Core\Traits\Migratable; |
|
8
|
|
|
use PWWEB\Localisation\Contracts\Language as LanguageContract; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* App\Models\Pwweb\Localisation\Models\Language Model. |
|
12
|
|
|
* |
|
13
|
|
|
* Standard Language Model. |
|
14
|
|
|
* |
|
15
|
|
|
* @author Frank Pillukeit <[email protected]> |
|
16
|
|
|
* @author Richard Browne <[email protected] |
|
17
|
|
|
* @copyright 2020 pw-websolutions.com |
|
18
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
19
|
|
|
* @property \Illuminate\Database\Eloquent\Collection countries |
|
20
|
|
|
* @property string name |
|
21
|
|
|
* @property string locale |
|
22
|
|
|
* @property string abbreviation |
|
23
|
|
|
* @property bool installed |
|
24
|
|
|
* @property bool active |
|
25
|
|
|
* @property bool standard |
|
26
|
|
|
*/ |
|
27
|
|
|
class Language extends Model implements LanguageContract |
|
28
|
|
|
{ |
|
29
|
|
|
use Migratable; |
|
30
|
|
|
|
|
31
|
|
|
const CREATED_AT = 'created_at'; |
|
32
|
|
|
const UPDATED_AT = 'updated_at'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The attributes that can be filled. |
|
36
|
|
|
* |
|
37
|
|
|
* @var string[] |
|
38
|
|
|
*/ |
|
39
|
|
|
public $fillable = [ |
|
40
|
|
|
'name', |
|
41
|
|
|
'locale', |
|
42
|
|
|
'abbreviation', |
|
43
|
|
|
'installed', |
|
44
|
|
|
'active', |
|
45
|
|
|
'standard', |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The attributes that should be casted to native types. |
|
50
|
|
|
* |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $casts = [ |
|
54
|
|
|
'id' => 'integer', |
|
55
|
|
|
'name' => 'string', |
|
56
|
|
|
'locale' => 'string', |
|
57
|
|
|
'abbreviation' => 'string', |
|
58
|
|
|
'installed' => 'boolean', |
|
59
|
|
|
'active' => 'boolean', |
|
60
|
|
|
'standard' => 'boolean', |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Validation rules. |
|
65
|
|
|
* |
|
66
|
|
|
* @var array |
|
67
|
|
|
*/ |
|
68
|
|
|
public static $rules = [ |
|
69
|
|
|
'name' => 'required', |
|
70
|
|
|
'locale' => 'required', |
|
71
|
|
|
'abbreviation' => 'required', |
|
72
|
|
|
'installed' => 'required', |
|
73
|
|
|
'active' => 'required', |
|
74
|
|
|
'standard' => 'required', |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Constructor. |
|
79
|
|
|
* |
|
80
|
|
|
* @param array $attributes additional attributes for model initialisation |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function __construct(array $attributes = []) |
|
85
|
|
|
{ |
|
86
|
|
|
parent::__construct($attributes); |
|
87
|
|
|
|
|
88
|
|
|
$this->setTable(config('pwweb.localisation.table_names.languages')); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Accessor for linked Country model. |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
95
|
|
|
**/ |
|
96
|
|
|
public function countries(): BelongsToMany |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->belongsToMany(config('pwweb.localisation.models.country'), 'system_localisation_country_languages'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|