hasSetMutator($key)) { $method = 'set' . Str::studly($key) . 'Attribute'; $this->{$method}($value); } else { $this->attributes[$key] = $value; } return $this; } /** * Determine if a set mutator exists for an attribute. * * @param string $key * @return bool */ public function hasSetMutator($key) { return method_exists($this, 'set' . Str::studly($key) . 'Attribute'); } /** * Get a plain attribute (not a relationship). * * @param string $key * @return mixed */ public function getAttribute($key) { $value = array_get($this->attributes, $key, null); if ($this->hasGetMutator($key)) { return $this->mutateAttribute($key, $value); } return $value; } /** * Get the value of an attribute using its mutator. * * @param string $key * @param mixed $value * @return mixed */ protected function mutateAttribute($key, $value) { return $this->{'get' . Str::studly($key) . 'Attribute'}($value); } /** * Determine if a get mutator exists for an attribute. * * @param string $key * @return bool */ public function hasGetMutator($key) { return method_exists($this, 'get' . Str::studly($key) . 'Attribute'); } /** * Dynamically retrieve attributes on the model. * * @param string $key * @return mixed */ public function __get($key) { return $this->getAttribute($key); } /** * Dynamically set attributes on the model. * * @param string $key * @param mixed $value * @return void */ public function __set($key, $value) { $this->setAttribute($key, $value); } public function __toString() { return $this->toJson(); } }