1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Language Entity. |
4
|
|
|
* |
5
|
|
|
* @package App\Entities\Language |
6
|
|
|
* |
7
|
|
|
* @author Nick Menke <[email protected]> |
8
|
|
|
* @copyright 2018-2020 Nick Menke |
9
|
|
|
* |
10
|
|
|
* @link https://github.com/nlmenke/vertebrae |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace App\Entities\Language; |
16
|
|
|
|
17
|
|
|
use App\Entities\AbstractEntity; |
18
|
|
|
use App\Entities\Country\Country; |
19
|
|
|
use App\Entities\Locale\Locale; |
20
|
|
|
use Illuminate\Database\Eloquent\Collection; |
21
|
|
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough; |
22
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The Language entity class. |
26
|
|
|
* |
27
|
|
|
* This class contains any functions required to access and manipulate language |
28
|
|
|
* models. |
29
|
|
|
* |
30
|
|
|
* @since x.x.x introduced |
31
|
|
|
*/ |
32
|
|
|
class Language extends AbstractEntity |
33
|
|
|
{ |
34
|
|
|
use SoftDeletes; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The attributes that are mass assignable. |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $fillable = [ |
42
|
|
|
'iso_alpha_2', |
43
|
|
|
'iso_alpha_3', |
44
|
|
|
'name', |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The country relationship instance. |
49
|
|
|
* |
50
|
|
|
* @return HasManyThrough |
51
|
|
|
*/ |
52
|
4 |
|
public function countries(): HasManyThrough |
53
|
|
|
{ |
54
|
4 |
|
return $this->hasManyThrough(Country::class, Locale::class, 'language_id', 'id', 'id', 'country_id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the countries attribute. |
59
|
|
|
* |
60
|
|
|
* @return Country[]|Collection |
61
|
|
|
*/ |
62
|
|
|
public function getCountries() |
63
|
|
|
{ |
64
|
|
|
return $this->getAttribute('countries'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the iso_alpha_2 attribute. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
public function getIsoAlpha2(): string |
73
|
|
|
{ |
74
|
|
|
return $this->getAttribute('iso_alpha_2'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get the iso_alpha_3 attribute. |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
public function getIsoAlpha3(): string |
83
|
|
|
{ |
84
|
|
|
return $this->getAttribute('iso_alpha_3'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the name attribute. |
89
|
|
|
* |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getName(): string |
93
|
|
|
{ |
94
|
|
|
return $this->getAttribute('name'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|