Skip to content

Commit

Permalink
check if month enum exists (since nestbot\carbon:^3.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
malkhazidartsmelidze committed Oct 15, 2024
1 parent e645708 commit 703c5dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions tests/Integration/Database/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

1 comment on commit 703c5dd

@shaedrich
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Please sign in to comment.