|
@@ 58-72 (lines=15) @@
|
| 55 |
|
* @param mixed $value |
| 56 |
|
* @return $this |
| 57 |
|
*/ |
| 58 |
|
public function setAttribute($key, $value) |
| 59 |
|
{ |
| 60 |
|
// First we will check for the presence of a mutator for the set operation |
| 61 |
|
// which simply lets the developers tweak the attribute as it is set on |
| 62 |
|
// the model, such as "json_encoding" an listing of data for storage. |
| 63 |
|
if ($this->hasSetMutator($key)) { |
| 64 |
|
$method = 'set' . studly_case($key) . 'Attribute'; |
| 65 |
|
|
| 66 |
|
return $this->{$method}($value); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
$this->attributes[$key] = $value; |
| 70 |
|
|
| 71 |
|
return $this; |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
/** |
| 75 |
|
* Determine if a set mutator exists for an attribute. |
|
@@ 107-120 (lines=14) @@
|
| 104 |
|
* @param string $key |
| 105 |
|
* @return mixed |
| 106 |
|
*/ |
| 107 |
|
public function getAttribute($key) |
| 108 |
|
{ |
| 109 |
|
$value = $this->getAttributeValue($key); |
| 110 |
|
|
| 111 |
|
// First we will check for the presence of a mutator for the set operation |
| 112 |
|
// which simply lets the developers tweak the attribute as it is set. |
| 113 |
|
if ($this->hasGetMutator($key)) { |
| 114 |
|
$method = 'get' . studly_case($key) . 'Attribute'; |
| 115 |
|
|
| 116 |
|
return $this->{$method}($value); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
return $value; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
/** |
| 123 |
|
* Get an attribute from the $attributes array. |