Skip to content

Commit

Permalink
orWhereDate should accept only two arguments (#24043)
Browse files Browse the repository at this point in the history
  • Loading branch information
binotaliu authored and taylorotwell committed Apr 29, 2018
1 parent 4faf96d commit e7d8a87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,10 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
*
* @param string $column
* @param string $operator
* @param string $value
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|static
*/
public function orWhereDate($column, $operator, $value)
public function orWhereDate($column, $operator, $value = null)
{
list($value, $operator) = $this->prepareValueAndOperator(
$value, $operator, func_num_args() == 2
Expand Down
19 changes: 19 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,25 @@ public function testDateBasedWheresAcceptsTwoArguments()
$this->assertEquals('select * from `users` where year(`created_at`) = ?', $builder->toSql());
}

public function testDateBasedOrWheresAcceptsTwoArguments()
{
$builder = $this->getMySqlBuilder();
$builder->select('*')->from('users')->where('id', 1)->orWhereDate('created_at', 1);
$this->assertEquals('select * from `users` where `id` = ? or date(`created_at`) = ?', $builder->toSql());

$builder = $this->getMySqlBuilder();
$builder->select('*')->from('users')->where('id', 1)->orWhereDay('created_at', 1);
$this->assertEquals('select * from `users` where `id` = ? or day(`created_at`) = ?', $builder->toSql());

$builder = $this->getMySqlBuilder();
$builder->select('*')->from('users')->where('id', 1)->orWhereMonth('created_at', 1);
$this->assertEquals('select * from `users` where `id` = ? or month(`created_at`) = ?', $builder->toSql());

$builder = $this->getMySqlBuilder();
$builder->select('*')->from('users')->where('id', 1)->orWhereyear('created_at', 1);
$this->assertEquals('select * from `users` where `id` = ? or year(`created_at`) = ?', $builder->toSql());
}

public function testDateBasedWheresExpressionIsNotBound()
{
$builder = $this->getBuilder();
Expand Down

0 comments on commit e7d8a87

Please sign in to comment.