Example #1
0
 /**
  * Ví dụ đối với enum 'language'
  * - Attribute của model: language_id
  * - Khi $model->present()->language: tự động lấy 'title' của enum đó
  * - Khi $model->present()->language_params: tự động lấy 'params' của enum đó
  *
  * @param string $property
  *
  * @return mixed
  */
 public function __get($property)
 {
     if (method_exists($this, $property)) {
         return $this->{$property}();
     } else {
         if (substr($property, -7) === '_params') {
             // get enum params
             $property_id = substr($property, 0, -7) . '_id';
             $column = 'params';
         } else {
             // get enum title
             $property_id = "{$property}_id";
             $column = 'title';
         }
         if (in_array($property_id, $this->entity->getEnumAttributes())) {
             return $this->entity->getEnumValue($property_id, $column);
         } else {
             // fallback to model
             return $this->entity->{$property};
         }
     }
 }