$datum) { $this->set($key, $datum); } } public function toArray() { $ar = []; foreach ($this->getProperties() as $key) { if (isset($this->$key)) { $ar[Str::snake($key)] = $this->get($key); } } return $ar; } public function toJson($options = 0) { return json_encode($this->toArray(), $options); } public function __get($name) { return $this->get($name); } public function get($name) { $property = Str::camel($name); if (property_exists($this, $property)) { return $this->{$property}; } throw new \Exception('Property ' . $property . ' does not exist on ' . get_class($this)); } public function __set($name, $value) { return $this->set($name, $value); } public function set($name, $value) { $property = Str::camel($name); if (!property_exists($this, $property)) { throw new \Exception('Can\'t set property ' . $property . ' that does not exist on ' . get_class($this)); } $this->{$property} = $value; } private function getProperties() { return array_keys(get_object_vars($this)); } }