diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index de3ae0b839b9..0a407d8f2184 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1316,7 +1316,7 @@ public function whereBetween($column, iterable $values, $boolean = 'and', $not = $type = 'between'; if ($values instanceof CarbonPeriod) { - $values = [$values->start, $values->end]; + $values = [$values->getStartDate(), $values->getEndDate()]; } $this->wheres[] = compact('type', 'column', 'values', 'boolean', 'not'); @@ -2381,7 +2381,7 @@ public function havingBetween($column, iterable $values, $boolean = 'and', $not $type = 'between'; if ($values instanceof CarbonPeriod) { - $values = [$values->start, $values->end]; + $values = [$values->getStartDate(), $values->getEndDate()]; } $this->havings[] = compact('type', 'column', 'values', 'boolean', 'not'); diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index cbf772ba572a..1583efb63b7d 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -771,17 +771,17 @@ public function testWhereBetweens() $this->assertEquals([], $builder->getBindings()); $builder = $this->getBuilder(); - $period = now()->toPeriod(now()->addDay()); + $period = now()->startOfDay()->toPeriod(now()->addDay()->startOfDay()); $builder->select('*')->from('users')->whereBetween('created_at', $period); $this->assertSame('select * from "users" where "created_at" between ? and ?', $builder->toSql()); - $this->assertEquals([$period->start, $period->end], $builder->getBindings()); + $this->assertEquals([now()->startOfDay(), now()->addDay()->startOfDay()], $builder->getBindings()); // custom long carbon period date $builder = $this->getBuilder(); - $period = now()->toPeriod(now()->addMonth()); + $period = now()->startOfDay()->toPeriod(now()->addMonth()->startOfDay()); $builder->select('*')->from('users')->whereBetween('created_at', $period); $this->assertSame('select * from "users" where "created_at" between ? and ?', $builder->toSql()); - $this->assertEquals([$period->start, $period->end], $builder->getBindings()); + $this->assertEquals([now()->startOfDay(), now()->addMonth()->startOfDay()], $builder->getBindings()); $builder = $this->getBuilder(); $builder->select('*')->from('users')->whereBetween('id', collect([1, 2]));