/** * 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()); }
/** * In addition to the testBleamble() test, you can configure what fields you want generated. */ public function testBlameableConfigurable() { $this->schemaBuilder->create($this->tableName, function (Blueprint $table) { $table->blameable(['created']); }); $this->assertTrue($this->schemaBuilder->hasColumn($this->tableName, 'created_by')); $this->assertFalse($this->schemaBuilder->hasColumn($this->tableName, 'updated_by')); $this->assertFalse($this->schemaBuilder->hasColumn($this->tableName, 'deleted_by')); $this->schemaBuilder->drop($this->tableName); $this->schemaBuilder->create($this->tableName, function (Blueprint $table) { $table->blameable(['created', 'updated']); }); $this->assertTrue($this->schemaBuilder->hasColumn($this->tableName, 'created_by')); $this->assertTrue($this->schemaBuilder->hasColumn($this->tableName, 'updated_by')); $this->assertFalse($this->schemaBuilder->hasColumn($this->tableName, 'deleted_by')); $this->schemaBuilder->drop($this->tableName); $this->schemaBuilder->create($this->tableName, function (Blueprint $table) { $table->blameable(['deleted', 'updated']); }); $this->assertFalse($this->schemaBuilder->hasColumn($this->tableName, 'created_by')); $this->assertTrue($this->schemaBuilder->hasColumn($this->tableName, 'updated_by')); $this->assertTrue($this->schemaBuilder->hasColumn($this->tableName, 'deleted_by')); }
/** * Determine if the given table has a given column. * * @param string $table * @param string $column * @return bool * @static */ public static function hasColumn($table, $column) { return \Illuminate\Database\Schema\Builder::hasColumn($table, $column); }
/** * Check if the given model talbe has the given column. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param string $column * @return bool */ protected function hasColumn(AuthenticatableContract $user, $column) { return $this->schema->hasColumn($user->getTable(), $column); }
/** * Determine if the given table has a given column. * * @param string $table * @param string $column * * @return bool */ public function hasColumn($table, $column) { return static::$schema->hasColumn($table, $column); }