Skip to content

Commit 2692777

Browse files
committed
Adding nullable method to Blueprint, fixes #90
1 parent 26b19c6 commit 2692777

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/Jenssegers/Mongodb/Schema/Blueprint.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(Connection $connection, $collection)
4444
*
4545
* @param string|array $columns
4646
* @param array $options
47-
* @return bool
47+
* @return Blueprint
4848
*/
4949
public function index($columns = null, $options = array())
5050
{
@@ -72,7 +72,7 @@ public function index($columns = null, $options = array())
7272
* Indicate that the given index should be dropped.
7373
*
7474
* @param string|array $columns
75-
* @return bool
75+
* @return Blueprint
7676
*/
7777
public function dropIndex($columns = null)
7878
{
@@ -90,7 +90,7 @@ public function dropIndex($columns = null)
9090
* Specify a unique index for the collection.
9191
*
9292
* @param string|array $columns
93-
* @return bool
93+
* @return Blueprint
9494
*/
9595
public function unique($columns = null, $name = null)
9696
{
@@ -104,7 +104,7 @@ public function unique($columns = null, $name = null)
104104
* Specify a non blocking index for the collection.
105105
*
106106
* @param string|array $columns
107-
* @return bool
107+
* @return Blueprint
108108
*/
109109
public function background($columns = null)
110110
{
@@ -118,7 +118,7 @@ public function background($columns = null)
118118
* Specify a sparse index for the collection.
119119
*
120120
* @param string|array $columns
121-
* @return bool
121+
* @return Blueprint
122122
*/
123123
public function sparse($columns = null)
124124
{
@@ -134,7 +134,7 @@ public function sparse($columns = null)
134134
*
135135
* @param string|array $columns
136136
* @param int $seconds
137-
* @return bool
137+
* @return Blueprint
138138
*/
139139
public function expire($columns, $seconds)
140140
{
@@ -168,6 +168,16 @@ public function drop()
168168
$this->collection->drop();
169169
}
170170

171+
/**
172+
* Allow an attribute to be null, does not do anything.
173+
*
174+
* @return Blueprint
175+
*/
176+
public function nullable()
177+
{
178+
return $this;
179+
}
180+
171181
/**
172182
* Add a new column to the blueprint.
173183
*

tests/SchemaTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ public function testExpire()
9292
$this->assertEquals(60, $index['expireAfterSeconds']);
9393
}
9494

95+
public function testSoftDeletes()
96+
{
97+
Schema::collection('newcollection', function($collection)
98+
{
99+
$collection->softDeletes();
100+
});
101+
102+
Schema::collection('newcollection', function($collection)
103+
{
104+
$collection->string('email')->nullable()->index();
105+
});
106+
107+
$index = $this->getIndex('newcollection', 'email');
108+
$this->assertEquals(1, $index['key']['email']);
109+
}
110+
95111
public function testFluent()
96112
{
97113
Schema::collection('newcollection', function($collection)

0 commit comments

Comments
 (0)