diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 1025915ed919..3362f025d368 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1047,6 +1047,23 @@ public function whereDay($column, $operator, $value = null, $boolean = 'and') return $this->addDateBasedWhere('Day', $column, $operator, $value, $boolean); } + /** + * Add an "or where day" statement to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereDay($column, $operator, $value = null) + { + list($value, $operator) = $this->prepareValueAndOperator( + $value, $operator, func_num_args() == 2 + ); + + return $this->addDateBasedWhere('Day', $column, $operator, $value, 'or'); + } + /** * Add a "where month" statement to the query. * @@ -1065,6 +1082,23 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and') return $this->addDateBasedWhere('Month', $column, $operator, $value, $boolean); } + /** + * Add an "or where month" statement to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereMonth($column, $operator, $value = null) + { + list($value, $operator) = $this->prepareValueAndOperator( + $value, $operator, func_num_args() == 2 + ); + + return $this->addDateBasedWhere('Month', $column, $operator, $value, 'or'); + } + /** * Add a "where year" statement to the query. * @@ -1083,6 +1117,23 @@ public function whereYear($column, $operator, $value = null, $boolean = 'and') return $this->addDateBasedWhere('Year', $column, $operator, $value, $boolean); } + /** + * Add an "or where year" statement to the query. + * + * @param string $column + * @param string $operator + * @param mixed $value + * @return \Illuminate\Database\Query\Builder|static + */ + public function orWhereYear($column, $operator, $value = null) + { + list($value, $operator) = $this->prepareValueAndOperator( + $value, $operator, func_num_args() == 2 + ); + + return $this->addDateBasedWhere('Year', $column, $operator, $value, 'or'); + } + /** * Add a date based (year, month, day, time) statement to the query. * diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index bec6b3bdff2f..6c0fd656d4ae 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -308,6 +308,14 @@ public function testWhereDayMySql() $this->assertEquals([0 => 1], $builder->getBindings()); } + public function testOrWhereDayMySql() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereDay('created_at', '=', 1)->orWhereDay('created_at', '=', 2); + $this->assertEquals('select * from `users` where day(`created_at`) = ? or day(`created_at`) = ?', $builder->toSql()); + $this->assertEquals([0 => 1, 1 => 2], $builder->getBindings()); + } + public function testWhereMonthMySql() { $builder = $this->getMySqlBuilder(); @@ -316,6 +324,14 @@ public function testWhereMonthMySql() $this->assertEquals([0 => 5], $builder->getBindings()); } + public function testOrWhereMonthMySql() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereMonth('created_at', '=', 5)->orWhereMonth('created_at', '=', 6); + $this->assertEquals('select * from `users` where month(`created_at`) = ? or month(`created_at`) = ?', $builder->toSql()); + $this->assertEquals([0 => 5, 1 => 6], $builder->getBindings()); + } + public function testWhereYearMySql() { $builder = $this->getMySqlBuilder(); @@ -324,6 +340,14 @@ public function testWhereYearMySql() $this->assertEquals([0 => 2014], $builder->getBindings()); } + public function testOrWhereYearMySql() + { + $builder = $this->getMySqlBuilder(); + $builder->select('*')->from('users')->whereYear('created_at', '=', 2014)->orWhereYear('created_at', '=', 2015); + $this->assertEquals('select * from `users` where year(`created_at`) = ? or year(`created_at`) = ?', $builder->toSql()); + $this->assertEquals([0 => 2014, 1 => 2015], $builder->getBindings()); + } + public function testWhereTimeMySql() { $builder = $this->getMySqlBuilder();