Browse Source

add default value for index names.

Taylor Otwell 13 years ago
parent
commit
b29f8a88fe
1 changed files with 13 additions and 5 deletions
  1. 13 5
      laravel/database/schema/table.php

+ 13 - 5
laravel/database/schema/table.php

@@ -79,7 +79,7 @@ class Table {
 	 * @param  string        $name
 	 * @return Fluent
 	 */
-	public function unique($columns, $name)
+	public function unique($columns, $name = null)
 	{
 		return $this->key(__FUNCTION__, $columns, $name);
 	}
@@ -91,7 +91,7 @@ class Table {
 	 * @param  string        $name
 	 * @return Fluent
 	 */
-	public function fulltext($columns, $name)
+	public function fulltext($columns, $name = null)
 	{
 		return $this->key(__FUNCTION__, $columns, $name);
 	}
@@ -103,7 +103,7 @@ class Table {
 	 * @param  string        $name
 	 * @return Fluent
 	 */
-	public function index($columns, $name)
+	public function index($columns, $name = null)
 	{
 		return $this->key(__FUNCTION__, $columns, $name);
 	}
@@ -118,9 +118,17 @@ class Table {
 	 */
 	public function key($type, $columns, $name)
 	{
-		$parameters = array('name' => $name, 'columns' => (array) $columns);
+		$columns = (array) $columns;
 
-		return $this->command($type, $parameters);
+		// If no index name was specified, we will concatenate the columns and
+		// append the index type to the name to generate a unique name for
+		// the index that can be used when dropping indexes.
+		if (is_null($name))
+		{
+			$name = implode('_', $columns).'_'.$type;
+		}
+
+		return $this->command($type, compact('name', 'columns'));
 	}
 
 	/**