Created
December 9, 2013 14:07
-
-
Save MauMaGau/7872725 to your computer and use it in GitHub Desktop.
Laravel Illuminate Schema : Modify nullable
This file contains 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
**Migration code** | |
<?php | |
Schema::table('users', function(Blueprint $table) | |
{ | |
$table->setNullable('username', true); | |
}); | |
**\Illuminate\Database\Schema\Blueprint** | |
<?php | |
public function setNullable($column_name, $setNullable=true) | |
{ | |
return $this->addCommand('setNullable', compact('column_name', 'setNullable')); | |
} | |
**\Illuminate\Database\Schema\Grammars\MySqlGrammar.php** | |
<?php | |
public function compileSetNullable(Blueprint $blueprint, Fluent $command) | |
{ | |
$column_name = $command->column_name; | |
$setNull = $command->setNullable ? 'default null' : 'not null'; | |
$table = $this->wrapTable($blueprint); | |
return "alter table {$table} modify {$column_name} varchar(255) ".$setNull; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment