Commit c9333002 authored by Jens Segers's avatar Jens Segers

Preparing for laravel 4.1, fixes #60

parent 1089ee3b
...@@ -25,4 +25,4 @@ ...@@ -25,4 +25,4 @@
} }
}, },
"minimum-stability": "dev" "minimum-stability": "dev"
} }
\ No newline at end of file
...@@ -23,5 +23,9 @@ ...@@ -23,5 +23,9 @@
<testsuite name="cache"> <testsuite name="cache">
<directory>tests/CacheTest.php</directory> <directory>tests/CacheTest.php</directory>
</testsuite> </testsuite>
<testsuite name="builder">
<directory>tests/QueryBuilderTest.php</directory>
<directory>tests/QueryTest.php</directory>
</testsuite>
</testsuites> </testsuites>
</phpunit> </phpunit>
...@@ -277,13 +277,14 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -277,13 +277,14 @@ class Builder extends \Illuminate\Database\Query\Builder {
* @param string $column * @param string $column
* @param array $values * @param array $values
* @param string $boolean * @param string $boolean
* @return \Illuminate\Database\Query\Builder * @param bool $not
* @return Builder
*/ */
public function whereBetween($column, array $values, $boolean = 'and') public function whereBetween($column, array $values, $boolean = 'and', $not = false)
{ {
$type = 'between'; $type = 'between';
$this->wheres[] = compact('column', 'type', 'boolean', 'values'); $this->wheres[] = compact('column', 'type', 'boolean', 'values', 'not');
return $this; return $this;
} }
...@@ -739,11 +740,32 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -739,11 +740,32 @@ class Builder extends \Illuminate\Database\Query\Builder {
{ {
extract($where); extract($where);
return array( if ($not)
$column => array( {
'$gte' => $values[0], return array(
'$lte' => $values[1]) '$or' => array(
array(
$column => array(
'$lte' => $values[0]
)
),
array(
$column => array(
'$gte' => $values[1]
)
)
)
); );
}
else
{
return array(
$column => array(
'$gte' => $values[0],
'$lte' => $values[1]
)
);
}
} }
protected function compileWhereRaw($where) protected function compileWhereRaw($where)
......
...@@ -103,6 +103,10 @@ class QueryTest extends PHPUnit_Framework_TestCase { ...@@ -103,6 +103,10 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$users = User::whereBetween('age', array(13, 23))->get(); $users = User::whereBetween('age', array(13, 23))->get();
$this->assertEquals(2, count($users)); $this->assertEquals(2, count($users));
// testing whereNotBetween for version 4.1
$users = User::whereBetween('age', array(0, 25), 'and', true)->get();
$this->assertEquals(6, count($users));
} }
public function testIn() public function testIn()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment