Passed
Push — master ( c8fc29...ea1130 )
by F
03:55
created

Language::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PWWEB\Localisation\Models;
4
5
use Eloquent as Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
7
use PWWEB\Localisation\Contracts\Language as LanguageContract;
8
9
/**
10
 * App\Models\Pwweb\Localisation\Models\Language Model.
11
 *
12
 * Standard Language Model.
13
 *
14
 * @package   pwweb/localisation
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 systemLocalisationCountries
20
 * @property string name
21
 * @property string locale
22
 * @property string abbreviation
23
 * @property boolean installed
24
 * @property boolean active
25
 * @property boolean standard
26
 */
27
28
class Language extends Model implements LanguageContract
29
{
30
    const CREATED_AT = 'created_at';
31
    const UPDATED_AT = 'updated_at';
32
33
    public $fillable = [
34
        'name',
35
        'locale',
36
        'abbreviation',
37
        'installed',
38
        'active',
39
        'standard'
40
    ];
41
42
    /**
43
     * The attributes that should be casted to native types.
44
     *
45
     * @var array
46
     */
47
    protected $casts = [
48
        'id' => 'integer',
49
        'name' => 'string',
50
        'locale' => 'string',
51
        'abbreviation' => 'string',
52
        'installed' => 'boolean',
53
        'active' => 'boolean',
54
        'standard' => 'boolean'
55
    ];
56
57
    /**
58
     * Validation rules.
59
     *
60
     * @var array
61
     */
62
    public static $rules = [
63
        'name' => 'required',
64
        'locale' => 'required',
65
        'abbreviation' => 'required',
66
        'installed' => 'required',
67
        'active' => 'required',
68
        'standard' => 'required'
69
    ];
70
71
    /**
72
     * Constructor.
73
     *
74
     * @param array $attributes additional attributes for model initialisation
75
     *
76
     * @return void
77
     */
78
    public function __construct(array $attributes = [])
79
    {
80
        parent::__construct($attributes);
81
82
        $this->setTable(config('pwweb.localisation.table_names.languages'));
83
    }
84
85
    /**
86
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
87
     **/
88
    public function countries() : BelongsToMany
89
    {
90
        return $this->belongsToMany(\PWWEB\Localisation\Models\Country::class, 'system_localisation_country_languages');
91
    }
92
}
93