Skip to content

Commit

Permalink
[5.6] Operator optional! (#22378)
Browse files Browse the repository at this point in the history
* Update Builder.php

* add test whereTime Operator optional to mysql and postgres

* change singature orWhereTime
  • Loading branch information
emtudo authored and taylorotwell committed Dec 10, 2017
1 parent ca5ecd9 commit c614475
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,16 @@ public function orWhereDate($column, $operator, $value)
*
* @param string $column
* @param string $operator
* @param int $value
* @param mixed $value
* @param string $boolean
* @return \Illuminate\Database\Query\Builder|static
*/
public function whereTime($column, $operator, $value, $boolean = 'and')
public function whereTime($column, $operator, $value = null, $boolean = 'and')
{
list($value, $operator) = $this->prepareValueAndOperator(
$value, $operator, func_num_args() == 2
);

return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean);
}

Expand All @@ -1007,10 +1011,10 @@ public function whereTime($column, $operator, $value, $boolean = 'and')
*
* @param string $column
* @param string $operator
* @param int $value
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|static
*/
public function orWhereTime($column, $operator, $value)
public function orWhereTime($column, $operator, $value = null)
{
return $this->whereTime($column, $operator, $value, 'or');
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ public function testWhereTimeMySql()
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereTimeOperatorOptionalMySql()
{
$builder = $this->getMySqlBuilder();
$builder->select('*')->from('users')->whereTime('created_at', '22:00');
$this->assertEquals('select * from `users` where time(`created_at`) = ?', $builder->toSql());
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereTimeOperatorOptionalPostgres()
{
$builder = $this->getPostgresBuilder();
$builder->select('*')->from('users')->whereTime('created_at', '22:00');
$this->assertEquals('select * from "users" where extract(time from "created_at") = ?', $builder->toSql());
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}

public function testWhereDatePostgres()
{
$builder = $this->getPostgresBuilder();
Expand Down

0 comments on commit c614475

Please sign in to comment.