Created
December 26, 2017 19:59
-
-
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]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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