diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 092b61130ca..6f8f629d0a5 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1881,7 +1881,7 @@ public function whereMonthBetween($column, iterable $values, $boolean = 'and', $ return $value->format('m'); } - if ($value instanceof Month) { + if (class_exists(Month::class) && $value instanceof Month) { $value = $value->value; } diff --git a/tests/Integration/Database/QueryBuilderTest.php b/tests/Integration/Database/QueryBuilderTest.php index 153ce55a591..a45b430a351 100644 --- a/tests/Integration/Database/QueryBuilderTest.php +++ b/tests/Integration/Database/QueryBuilderTest.php @@ -2,7 +2,6 @@ namespace Illuminate\Tests\Integration\Database; -use Carbon\Month; use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Database\MultipleRecordsFoundException; use Illuminate\Database\RecordsNotFoundException; @@ -333,7 +332,15 @@ public function testWhereMonthBetween() $this->assertSame(1, DB::table('posts')->whereMonthBetween('created_at', ['11', '12'])->count()); $this->assertSame(2, DB::table('posts')->whereMonthBetween('created_at', [1, '12'])->count()); $this->assertSame(1, DB::table('posts')->whereMonthBetween('created_at', [1, 3])->count()); - $this->assertSame(1, DB::table('posts')->whereMonthBetween('created_at', [Month::January, Month::April])->count()); + } + + public function testWhereMonthBetweenUsinCarbon() + { + if(! class_exists(\Carbon\Month::class)) { + $this->markTestSkipped('Carbon 3.0 is not installed.'); + } + + $this->assertSame(1, DB::table('posts')->whereMonthBetween('created_at', [\Carbon\Month::January, \Carbon\Month::March])->count()); } public function testWhereDayBetween()