/**
  * Rename a column.
  *
  * @param                     $table
  * @param FieldType           $type
  * @param AssignmentInterface $assignment
  */
 public function renameColumn($table, FieldType $type, AssignmentInterface $assignment)
 {
     $schema = $type->getSchema();
     $from = $assignment->getFieldType(true);
     if ($from->getColumnName() === $type->getColumnName()) {
         return;
     }
     $this->schema->table($table, function (Blueprint $table) use($schema, $from) {
         $schema->renameColumn($table, $from);
     });
 }
 /**
  * Drop the field type column from the table.
  *
  * @param Blueprint $table
  */
 public function dropColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Drop dat 'ole column.
     $table->dropColumn($this->fieldType->getColumnName());
 }
 /**
  * Restore the field type column to cache.
  *
  * @param Blueprint $table
  */
 public function restoreColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Translatable or no?
     $translatable = ends_with($table->getTable(), '_translations');
     // Restore the data.
     $results = $this->cache->get(__CLASS__ . $this->fieldType->getColumnName());
     foreach ($results as $result) {
         $result = (array) $result;
         $this->connection->table($table->getTable())->where($translatable ? 'entry_id' : 'id', array_pull($result, 'id'))->update($result);
     }
     $this->cache->forget(__CLASS__ . $this->fieldType->getColumnName());
 }
 /**
  * Get the database column name.
  *
  * @return null|string
  */
 public function getColumnName()
 {
     return parent::getColumnName() . '_id';
 }
Пример #5
0
 /**
  * Order a query in the given direction
  * by a field using this field type.
  *
  * @param Builder $query
  * @param         $direction
  */
 public function orderBy(Builder $query, $direction)
 {
     $query->orderBy($this->fieldType->getColumnName(), $direction);
 }