1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Gameap\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Sofa\Eloquence\Validable; |
7
|
|
|
use Sofa\Eloquence\Contracts\Validable as ValidableContract; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class GameMod |
11
|
|
|
* @package Gameap\Models |
12
|
|
|
* |
13
|
|
|
* @property integer $id |
14
|
|
|
* @property string $game_code |
15
|
|
|
* @property string $name |
16
|
|
|
* @property string $fast_rcon |
17
|
|
|
* @property string $vars |
18
|
|
|
* @property string $remote_repository |
19
|
|
|
* @property string $local_repository |
20
|
|
|
* @property string $kick_cmd |
21
|
|
|
* @property string $ban_cmd |
22
|
|
|
* @property string $chname_cmd |
23
|
|
|
* @property string $srestart_cmd |
24
|
|
|
* @property string $chmap_cmd |
25
|
|
|
* @property string $sendmsg_cmd |
26
|
|
|
* @property string $passwd_cmd |
27
|
|
|
*/ |
28
|
|
|
class GameMod extends Model implements ValidableContract |
29
|
|
|
{ |
30
|
|
|
use Validable; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var bool |
34
|
|
|
*/ |
35
|
|
|
public $timestamps = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The attributes that are mass assignable. |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $fillable = [ |
43
|
|
|
'name', 'game_code', |
44
|
|
|
'fast_rcon', 'vars', |
45
|
|
|
'remote_repository', 'local_repository', |
46
|
|
|
'kick_cmd', 'ban_cmd', 'chname_cmd', 'srestart_cmd', 'chmap_cmd', 'sendmsg_cmd', 'passwd_cmd' |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Validation rules |
51
|
|
|
* |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected static $rules = [ |
55
|
|
|
'name' => 'required|string|max:255|unique:game_mods', |
56
|
|
|
'game_code' => 'sometimes|string|max:255|exists:games,code', |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $casts = [ |
63
|
|
|
'vars' => 'array', |
64
|
|
|
'fast_rcon' => 'array', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* One to one relation |
69
|
|
|
* |
70
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
71
|
|
|
*/ |
72
|
|
|
public function game() |
73
|
|
|
{ |
74
|
|
|
return $this->belongsTo(Game::class, 'game_code', 'code'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* One to many relation |
79
|
|
|
* |
80
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
81
|
|
|
*/ |
82
|
|
|
public function servers() |
83
|
|
|
{ |
84
|
|
|
return $this->hasMany(Server::class); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Cast an attribute to a native PHP type. |
89
|
|
|
* |
90
|
|
|
* @param string $key |
91
|
|
|
* @param mixed $value |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
|
|
protected function castAttribute($key, $value) |
95
|
|
|
{ |
96
|
|
|
if ($this->getCastType($key) == 'array' && is_null($value)) { |
97
|
|
|
return []; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return parent::castAttribute($key, $value); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|