1
|
|
|
<?php namespace FreedomCore\TrinityCore\Character\Models; |
2
|
|
|
|
3
|
|
|
use Config; |
4
|
|
|
use Illuminate\Database\Eloquent\Model; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class CharacterBaseModel |
8
|
|
|
* @package FreedomCore\TrinityCore\Character\Models |
9
|
|
|
*/ |
10
|
|
|
abstract class CharacterBaseModel extends Model |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Connection name |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $connection = 'character'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Table name |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $table; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Table primary key |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $primaryKey; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Does that table supposed auto-increment |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $incrementing = false; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Doest that table includes timestamps generated |
39
|
|
|
* by Laravel |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
public $timestamps = false; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Columns which are allowed to be mass assigned |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $fillable = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Cast value to specified data type. |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
protected $casts = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Key for configuration file containing database |
58
|
|
|
* connection settings. |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
private $configurationKey = 'character.connections.character'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* CharacterBaseModel constructor. |
65
|
|
|
* @param array $attributes |
66
|
|
|
*/ |
67
|
|
|
public function __construct(array $attributes = []) |
68
|
|
|
{ |
69
|
|
|
parent::__construct($attributes); |
70
|
|
|
$this->getDatabaseConnection(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Fake ID incrementation |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
|
|
public function scopeIncrementID() |
78
|
|
|
{ |
79
|
|
|
if ($this->primaryKey) { |
80
|
|
|
return $this->max($this->primaryKey) + 1; |
81
|
|
|
} else { |
82
|
|
|
throw new \RuntimeException('Primary key is not set!'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get Database Connection Settings |
88
|
|
|
*/ |
89
|
|
|
protected function getDatabaseConnection() |
90
|
|
|
{ |
91
|
|
|
$existingConnections = Config::get('database.connections'); |
92
|
|
|
if (!array_key_exists('character', $existingConnections)) { |
93
|
|
|
Config::set('database.connections.character', Config::get($this->configurationKey)); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|