Skip to content

Instantly share code, notes, and snippets.

@calevano
Created December 26, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calevano/5ac7c58acbd28531f6d06ffcdcb08c7b to your computer and use it in GitHub Desktop.
Save calevano/5ac7c58acbd28531f6d06ffcdcb08c7b to your computer and use it in GitHub Desktop.
Laravel 5.2 Console Comand, Alter table with arguments, options... php artisan change-column-table [argument] [--options]
public function handle()
{
$tableName = $this->argument('table');
if ($tableName != null) {
$table = Schema::hasTable($tableName);
if ($table) {
$columnName = $this->option('column');
if ($columnName != null) {
$column = Schema::hasColumn($tableName, $columnName);
if ($column) {
$length = $this->option('length');
if ($length) {
$sql = "ALTER TABLE {$tableName} modify {$columnName} varchar({$length})";
DB::statement($sql);
$this->info("Se actualizo correctamente la longitud a " . $length . " de la columna " . $columnName . " en la tabla " . $tableName);
} else {
$this->error("No ingresaste la longitud de la columna");
}
} else {
$this->error("Tabla=" . $tableName . ", nombre de columna " . $columnName . " no existe");
}
} else {
$this->error("No ingresaste nombre la columna");
}
} else {
$this->error("Tabla " . $tableName . " no existe");
}
} else {
$this->error("No ingresaste nombre de la tabla");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment