1 | <?php |
||
18 | class MetaItem extends Model implements MetaItemContract |
||
19 | { |
||
20 | /** |
||
21 | * The attributes that are mass assignable. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $fillable = ['key', 'tag', 'value']; |
||
26 | |||
27 | /** |
||
28 | * The table associated with the model. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $table = 'meta'; |
||
33 | |||
34 | /** |
||
35 | * Parent model relation. |
||
36 | * |
||
37 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
38 | */ |
||
39 | 1 | public function model() |
|
40 | { |
||
41 | 1 | return $this->morphTo(); |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Get the value type registry. |
||
46 | * |
||
47 | * @return \BoxedCode\Eloquent\Meta\Types\Registry |
||
48 | */ |
||
49 | 54 | protected function getTypeRegistry() |
|
53 | |||
54 | /** |
||
55 | * Get the models value type class name. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | 54 | protected function getTypeClass() |
|
63 | |||
64 | /** |
||
65 | * Get the models value type instance. |
||
66 | * |
||
67 | * @return \BoxedCode\Eloquent\Meta\Contracts\Type |
||
68 | */ |
||
69 | 54 | protected function getTypeInstance() |
|
75 | |||
76 | /** |
||
77 | * Parse and get the value attribute. |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 7 | public function getValueAttribute() |
|
85 | |||
86 | /** |
||
87 | * Parse and set the value attribute. |
||
88 | * |
||
89 | * @param mixed $value |
||
90 | * @param string $type |
||
91 | */ |
||
92 | 54 | public function setValueAttribute($value, $type = null) |
|
93 | { |
||
94 | 54 | if (is_null($type) && ! isset($this->attributes['type'])) { |
|
95 | 54 | $registry = $this->getTypeRegistry(); |
|
96 | 54 | $this->attributes['type'] = $registry->findTypeFor($value)->getClass(); |
|
97 | 54 | } elseif (isset($type)) { |
|
98 | 1 | $this->attributes['type'] = $type; |
|
99 | 1 | } |
|
100 | |||
101 | 54 | return $this->getTypeInstance()->set($value); |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Get the value attribute by-passing any accessors. |
||
106 | * |
||
107 | * @return mixed |
||
108 | */ |
||
109 | 20 | public function getRawValue() |
|
113 | |||
114 | /** |
||
115 | * Set the value attribute by-passing the mutators. |
||
116 | * |
||
117 | * @param mixed $value |
||
118 | */ |
||
119 | 54 | public function setRawValue($value) |
|
123 | |||
124 | /** |
||
125 | * Create a new Eloquent Collection instance. |
||
126 | * |
||
127 | * @param array $models |
||
128 | * @return \Illuminate\Database\Eloquent\Collection |
||
129 | */ |
||
130 | 9 | public function newCollection(array $models = []) |
|
138 | |||
139 | /** |
||
140 | * Get the string value of the meta item. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | 1 | public function __toString() |
|
148 | } |
||
149 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.