/**
  * @param string $tableName
  * @return ColumnCollection
  */
 public function factory($tableName)
 {
     $table = $this->connection->getDoctrineSchemaManager()->listTableDetails($tableName);
     $schemas = $table->getColumns();
     list($foreignKeyColumns, $foreignTables) = $this->getForeignKeys($table);
     $indexes = Collection::make($table->getIndexes());
     $columns = ColumnCollection::make([]);
     foreach ($schemas as $column) {
         $column = $this->buildColumn($column, $foreignKeyColumns, $foreignTables, $indexes);
         $columns->push($column);
     }
     return $columns;
 }
 /**
  * @param string $table
  * @param integer $id
  * */
 protected function register($table, $id = null)
 {
     $this->buildInstances($table);
     $inputs = $this->service->getRegisterValues(Input::all());
     $rules = $this->columns->getValidateRules();
     $validator = Validator::make($inputs, $rules->toArray());
     if ($validator->fails()) {
         return Redirect::to($this->getUrl('form', $table, $id))->withErrors($validator->errors())->withInput();
     }
     try {
         $this->service->register($inputs, $id);
         if ($id) {
             $text = 'updated';
         } else {
             $text = 'created';
         }
         $message = ['type' => 'success', 'text' => $text];
         return Redirect::to($this->getUrl('index', $table))->with('message', $message);
     } catch (Exception $e) {
         $message = ['type' => 'danger', 'text' => 'error'];
         return Redirect::to(Request::getUri())->with('message', $message)->withInput();
     }
 }