$this->fill($attributes);
}
+ /**
+ * Create translated items as json.
+ *
+ * @param array $attributes
+ * @return static
+ */
+ public static function create(array $attributes = [])
+ {
+ $locale = $attributes['locale'] ?? \App::getLocale();
+ $attributes = array_except($attributes, ['locale']);
+ $non_translatable = [];
+
+ $model = new static();
+
+ // do the actual saving
+ foreach ($attributes as $attribute => $value) {
+ if ($model->isTranslatableAttribute($attribute)) { // the attribute is translatable
+ $model->setTranslation($attribute, $locale, $value);
+ } else { // the attribute is NOT translatable
+ $non_translatable[$attribute] = $value;
+ }
+ }
+ $model->fill($non_translatable)->save();
+
+ return $model;
+ }
+
+
public function setFields()
{
protected function _addTimestampsDatabaseColumns($table)
{
$options = ['notnull' => false];
- $table->addColumn(static::CREATED_AT, 'date', $options);
- $table->addColumn(static::UPDATED_AT, 'date', $options);
- $table->addColumn('deleted_at', 'date', $options);
+ $table->addColumn(static::CREATED_AT, 'datetime', $options);
+ $table->addColumn(static::UPDATED_AT, 'datetime', $options);
+ $table->addColumn('deleted_at', 'datetime', $options);
}
public function replicate(array $except = null)
case 'belongsTo':
return $this->belongsTo($field->getAttribute('model'), $field->getAttribute('name'));
case 'belongsToMany':
- return $this->belongsToMany($field->getAttribute('model'), $this->getRelationShipTable($field));
+ return $this->belongsToMany($field->getAttribute('model'), $this->getRelationShipTable($field))->withPivot([$this->getForeignKey(), self::_toModel($field->getAttribute('model'))->getForeignKey()]);
}
}