Skip to content

Instantly share code, notes, and snippets.

@MauMaGau
Last active December 30, 2015 19:19
Show Gist options
  • Save MauMaGau/7873463 to your computer and use it in GitHub Desktop.
Save MauMaGau/7873463 to your computer and use it in GitHub Desktop.
Laravel Illuminate Schema : add method to updateColumn
<?php
## Migration ##
Schema::table('users', function(Blueprint $table)
{
$table->updateColumn('username', 'string')->length(250)->nullable();
});
## \Illuminate\Support\Database\Schema\Blueprint.php ##
/**
* Indicate that the given columns should be altered.
*
* @param string $column_name
* @param string $type
* @return \Illuminate\Support\Fluent
*/
public function updateColumn($column_name, $type)
{
return $this->addCommand('updateColumn', compact('column_name', 'type'));
}
## \Illuminate\Database\Schema\Grammars\MySqlGrammar.php ##
/**
* Compile an update column command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileUpdateColumn(Blueprint $blueprint, Fluent $command)
{
$table = $this->wrapTable($blueprint);
$type = $this->{'type'.ucfirst($command->type)}($command);
return "alter table {$table} modify {$command->columnName} {$type}";
}
@sanjulika
Copy link

I am facing issue it, code is not working for me. migration is successfully run but not changing the datatype.

return $this->addModifiers($sql, $blueprint, $command); // where is addmodifier function??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment