|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 11/03/2016 |
|
6
|
|
|
* Time: 12:18. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Model; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Database\Eloquent\Model as EloquentModel; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class Setting. |
|
15
|
|
|
*/ |
|
16
|
|
|
class Setting extends EloquentModel |
|
17
|
|
|
{ |
|
18
|
|
|
protected $table = 'settings'; |
|
19
|
|
|
|
|
20
|
|
|
protected $dates = ['updated_at']; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* ==========================================================. |
|
24
|
|
|
* |
|
25
|
|
|
* GET THE ATTRIBUTES OF THE MODEL |
|
26
|
|
|
* |
|
27
|
|
|
* ========================================================== |
|
28
|
|
|
*/ |
|
29
|
|
|
public function id() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getAttribute('id'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function key() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->getAttribute('key'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function name() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->getAttribute('name'); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function value() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->getAttribute('value'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function description() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getAttribute('description'); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// shadow is the name - default -name, since php 5.6 does not support |
|
55
|
|
|
// the keywords as function names. |
|
56
|
|
|
public function shadow() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->getAttribute('default'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* If a value exists, return that, otherwise return shadow. |
|
63
|
|
|
* |
|
64
|
|
|
* @return mixed |
|
65
|
|
|
*/ |
|
66
|
|
|
public function current() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->value() ?: $this->shadow(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getUpdatedAt() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->getAttribute('updated_at'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* ==========================================================. |
|
78
|
|
|
* |
|
79
|
|
|
* SET THE ATTRIBUTES OF THE MODEL |
|
80
|
|
|
* |
|
81
|
|
|
* ========================================================== |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setKey($string) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->setAttribute('key', $string); |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function setName($string) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->setAttribute('name', $string); |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function setValue($string) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->setAttribute('value', $string); |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function setShadow(string $string) |
|
105
|
|
|
{ |
|
106
|
|
|
$this->setAttribute('default', $string); |
|
107
|
|
|
|
|
108
|
|
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function setDescription($string) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->setAttribute('description', $string); |
|
114
|
|
|
|
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
If used attribute cannot be found there are two main reasons: 1. there is a creating database migration missing or 2. there is a major typo in either the declaration or the usage.