/**
  * @param \Magia\Model\MagickEloquent $item
  */
 public function generateFields($item)
 {
     $fields = array();
     $table = $item->getTable();
     foreach ($item->getAttributes() as $index => $value) {
         $fields[] = $this->generateField($table, $index, $value);
     }
     foreach ($item->getRelations() as $relation => $relationModel) {
         $relationObject = $item->{$relation}();
         $fields[] = $this->generateFieldFromRelation($relation, $relationObject, $relationModel);
     }
     return $fields;
 }
 /**
  * @param \Illuminate\Database\Eloquent\Collection|static[] $collection
  */
 public function generateArrayData($collection)
 {
     $modelObject = $collection->first();
     $arrayData = array();
     foreach ($collection as $item) {
         $row = array();
         foreach ($modelObject->getListAttributes() as $index => $value) {
             $row[] = $item->{$index};
         }
         $pk = $modelObject->getPrimaryKey();
         $href = route('admin_edit', ['model' => $this->model->getUrlName(), 'id' => "{$pk}:{$item->{$pk}}"]);
         $row[] = "<a href='{$href}'>Editar</a>";
         $arrayData[] = $row;
     }
     return $arrayData;
 }
 public static function getModel($modelString)
 {
     $modelEloquent = new MagickEloquent();
     $model = $modelEloquent->cleanModel($modelString);
     $modelPath = '\\App\\' . $model;
     if (!class_exists($modelPath)) {
         throw new \Exception("Class {$modelPath} not found");
     }
     /* @var \Magia\Model\MagickEloquent $modelObject */
     $modelObject = new $modelPath();
     if (!is_a($modelObject, 'Magia\\Model\\MagickEloquent')) {
         throw new \Exception("Class {$model} is not a MagickEloquent Model");
     }
     $modelObject->setUrlName($modelString);
     return $modelObject;
 }
 public function modelList($model)
 {
     $model = MagickEloquent::getModel($model);
     $list = ModelListComposer::getList($model);
     return view("magia::list", array("list" => $list));
 }