Commit c9333002 authored by Jens Segers's avatar Jens Segers

Preparing for laravel 4.1, fixes #60

parent 1089ee3b
......@@ -25,4 +25,4 @@
}
},
"minimum-stability": "dev"
}
\ No newline at end of file
}
......@@ -23,5 +23,9 @@
<testsuite name="cache">
<directory>tests/CacheTest.php</directory>
</testsuite>
<testsuite name="builder">
<directory>tests/QueryBuilderTest.php</directory>
<directory>tests/QueryTest.php</directory>
</testsuite>
</testsuites>
</phpunit>
......@@ -277,13 +277,14 @@ class Builder extends \Illuminate\Database\Query\Builder {
* @param string $column
* @param array $values
* @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';
$this->wheres[] = compact('column', 'type', 'boolean', 'values');
$this->wheres[] = compact('column', 'type', 'boolean', 'values', 'not');
return $this;
}
......@@ -739,11 +740,32 @@ class Builder extends \Illuminate\Database\Query\Builder {
{
extract($where);
return array(
$column => array(
'$gte' => $values[0],
'$lte' => $values[1])
if ($not)
{
return array(
'$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)
......
......@@ -103,6 +103,10 @@ class QueryTest extends PHPUnit_Framework_TestCase {
$users = User::whereBetween('age', array(13, 23))->get();
$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()
......
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