Skip to content

Commit 0a0eb37

Browse files
committed
Merge pull request laravel#1365 from sdbondi/develop
Ref #649 - Added query builder support for BETWEEN clauses
2 parents ca44c93 + 5f48387 commit 0a0eb37

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

laravel/database/query.php

100644100755
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,67 @@ public function or_where_not_in($column, $values)
342342
{
343343
return $this->where_not_in($column, $values, 'OR');
344344
}
345+
346+
/**
347+
* Add a BETWEEN condition to the query
348+
*
349+
* @param string $column
350+
* @param mixed $min
351+
* @param mixed $max
352+
* @param string $connector
353+
* @param boolean $not
354+
* @return Query
355+
*/
356+
public function where_between($column, $min, $max, $connector = 'AND', $not = false)
357+
{
358+
$type = ($not) ? 'where_not_between' : 'where_between';
359+
360+
$this->wheres[] = compact('type', 'column', 'min', 'max', 'connector');
361+
362+
$this->bindings[] = $min;
363+
$this->bindings[] = $max;
364+
365+
return $this;
366+
}
367+
368+
/**
369+
* Add a OR BETWEEN condition to the query
370+
*
371+
* @param string $column
372+
* @param mixed $min
373+
* @param mixed $max
374+
* @return Query
375+
*/
376+
public function or_where_between($column, $min, $max)
377+
{
378+
return $this->where_between($column, $min, $max, 'OR');
379+
}
380+
381+
/**
382+
* Add a NOT BETWEEN condition to the query
383+
*
384+
* @param string $column
385+
* @param mixed $min
386+
* @param mixed $max
387+
* @return Query
388+
*/
389+
public function where_not_between($column, $min, $max, $connector = 'AND')
390+
{
391+
return $this->where_between($column, $min, $max, $connector, true);
392+
}
393+
394+
/**
395+
* Add a OR NOT BETWEEN condition to the query
396+
*
397+
* @param string $column
398+
* @param mixed $min
399+
* @param mixed $max
400+
* @return Query
401+
*/
402+
public function or_where_not_between($column, $min, $max)
403+
{
404+
return $this->where_not_between($column, $min, $max, 'OR');
405+
}
345406

346407
/**
347408
* Add a where null condition to the query.

laravel/database/query/grammars/grammar.php

100644100755
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,33 @@ protected function where_not_in($where)
242242
return $this->wrap($where['column']).' NOT IN ('.$parameters.')';
243243
}
244244

245+
/**
246+
* Compile a WHERE BETWEEN clause
247+
*
248+
* @param array $where
249+
* @return string
250+
*/
251+
protected function where_between($where)
252+
{
253+
$min = $this->parameter($where['min']);
254+
$max = $this->parameter($where['max']);
255+
256+
return $this->wrap($where['column']).' BETWEEN '.$min.' AND '.$max;
257+
}
258+
259+
/**
260+
* Compile a WHERE NOT BETWEEN clause
261+
* @param array $where
262+
* @return string
263+
*/
264+
protected function where_not_between($where)
265+
{
266+
$min = $this->parameter($where['min']);
267+
$max = $this->parameter($where['max']);
268+
269+
return $this->wrap($where['column']).' NOT BETWEEN '.$min.' AND '.$max;
270+
}
271+
245272
/**
246273
* Compile a WHERE NULL clause.
247274
*

0 commit comments

Comments
 (0)