Skip to content

Instantly share code, notes, and snippets.

@MauMaGau
Created December 9, 2013 14:07
Show Gist options
  • Save MauMaGau/7872725 to your computer and use it in GitHub Desktop.
Save MauMaGau/7872725 to your computer and use it in GitHub Desktop.
Laravel Illuminate Schema : Modify nullable
**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