return $field;
}
+ /**
+ * @param array $attributes
+ * @return Field
+ * @throws \Exception
+ */
public function addFakeField(array $attributes)
{
$attributes['fake'] = true;
public function setAttributeIfNotSet($key, $value)
{
$k = $this->_attribute($key);
- if ($this->getAttribute($key, null) !== null) {
+ if ($this->hasAttribute($key)) {
return;
}
$this->setAttribute($k, $value);
'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
'column_type' => $this->_columnType, 'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
'allow_null' => true,
- 'fake' => false, 'store_in' => false, 'attributes' => [],];
+ 'fake' => false, 'store_in' => 'extras', 'attributes' => [],];
}
public function __construct($attributes)
protected function _postSetAttributes()
{
- if ($this->getAttribute('fake', false) === true) {
+ if ($this->getAttribute('fake')) {
$this->setAttributeIfNotSet('store_in', 'extras');
}
if ($this->hasAttribute('when')) {
if (!isset($this->casts[$store_in])) {
$this->casts[$store_in] = 'array';
}
- if (!in_array($store_in, $this->fakeColumns)) {
- $this->fakeColumns[] = $store_in;
- }
+
+ $this->fakeColumns[$store_in] = true;
} else {
if ($field->getAttribute('fillable')) {
$this->fillable[] = $name;
}
}
- $fakeColumns = [];
-
foreach ($this->_fields as $field) {
if ($field->getRelationship() == 'belongsToMany') {
continue;
}
- if ($field->getAttribute('store_in', false) !== false) {
- $fakeColumns[] = $field->getAttribute('store_in');
+ if ($field->getAttribute('fake', false) !== false) {
continue;
}
$field->defineDbColumn($table);
}
- $fakeColumns = array_unique($fakeColumns);
- foreach ($fakeColumns as $fakeColumn) {
+ foreach ($this->fakeColumns as $fakeColumn => $true) {
$table->addColumn($fakeColumn, 'text');
}