diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index 00fe7c55e086..613d2b63a7fb 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -1673,6 +1673,23 @@ protected function createIndexName($type, array $columns) return str_replace(['-', '.'], '_', $index); } + /** + * Add a check constraint to the table. + * + * @param $checkName + * @param $constraint + * @return Fluent + */ + public function check($checkName, $constraint) + { + return $this->addCommand('check', compact('checkName', 'constraint')); + } + + public function dropCheck($checkName) + { + return $this->addCommand('dropCheck', compact('checkName')); + } + /** * Add a new column to the blueprint. * diff --git a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php index e01aa947fe35..d090f41d54c1 100755 --- a/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php @@ -578,6 +578,34 @@ public function compileTableComment(Blueprint $blueprint, Fluent $command) ); } + /** + * Compile a table level check command. + * + * @param Blueprint $blueprint + * @param Fluent $command + * @return string + */ + public function compileCheck(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return sprintf('alter table %s add constraint %s check (%s)', + $table, + $this->wrap($command->checkName), + $command->constraint + ); + } + + public function compileDropCheck(Blueprint $blueprint, Fluent $command) + { + $table = $this->wrapTable($blueprint); + + return sprintf('alter table %s drop constraint %s', + $table, + $this->wrap($command->checkName) + ); + } + /** * Quote-escape the given tables, views, or types. *