protected $_databaseUnique = false;
protected $_databaseIndex = false;
protected $_databaseDefault = null;
+ protected $_databaseLength = null;
/** @var bool|string|array */
protected $_cast = false;
'default' => null, 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
'allow_null' => true,
'can' => $this->_can, 'can_write' => $this->_canWrite, 'auth' => $this->_auth,
- 'database_type' => $this->_databaseType, 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex, 'database_default' => $this->_databaseDefault,
+ 'database_type' => $this->_databaseType, 'database_unique' => $this->_databaseUnique, 'database_index' => $this->_databaseIndex, 'database_default' => $this->_databaseDefault, 'database_length' => $this->_databaseLength,
'fake' => false, 'store_in' => 'extras', 'attributes' => []];
}
if ($default !== null) {
$attributes['default'] = $default;
}
+ $length = $this->getDatabaseLength();
+ if (null !== $length) {
+ $attributes['length'] = $length;
+ }
$table->addColumn($name,
CubistMagicAbstractModel::toDoctrineType($this->getDatabaseType()),
}
}
+ public function getDatabaseLength(){
+ return $this->getAttribute('database_length');
+ }
+
/**
* @return null|string
*/
protected $_columnType = 'select_from_array';
protected $_columnViewNamespace = CubistBackpackServiceProvider::NAMESPACE . '::columns';
protected $_databaseType = 'string';
+ protected $_databaseLength = 32;
protected $_multiple = false;
protected $_allowNull = true;
protected $_options = [];
}
}
+ public function getDatabaseLength()
+ {
+ $keys = array_keys($this->getAttribute('options'));
+ $max = 0;
+ foreach ($keys as $key) {
+ $max = max($max, mb_strlen($key));
+ }
+ return $max * 2;
+ }
+
+
public function getOptions()
{
return $this->_options;
protected $_columnType = 'select_from_array';
protected $_databaseType = 'string';
+ protected $_databaseLength=16;
protected $_multiple = false;
protected $_order = false;
protected $_allows_null = false;