© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
4 replies
Pascale

Problem with month translation in Filters - related to Carbon?

We have a very interesting issue with months translated through
src/Filters/QueryBuilder/Constraints/DateConstraint/Operators/IsMonthOperator.php:getMonths()
src/Filters/QueryBuilder/Constraints/DateConstraint/Operators/IsMonthOperator.php:getMonths()
:


protected function getMonths(): array
    {
        return collect(range(1, 12))
            ->mapWithKeys(fn (int $month): array => [
                $month => now()->setMonth($month)->getTranslatedMonthName(),
            ])
            ->all();
    }
protected function getMonths(): array
    {
        return collect(range(1, 12))
            ->mapWithKeys(fn (int $month): array => [
                $month => now()->setMonth($month)->getTranslatedMonthName(),
            ])
            ->all();
    }


Result:

The list of month is off since a little bit:

array(12) {
  [1]=>
  string(7) "January"
  [2]=>
  string(5) "March"
  [3]=>
  string(5) "March"
  [4]=>
  string(3) "May"
  [5]=>
  string(3) "May"
  [6]=>
  string(4) "July"
  [7]=>
  string(4) "July"
  [8]=>
  string(6) "August"
  [9]=>
  string(7) "October"
  [10]=>
  string(7) "October"
  [11]=>
  string(8) "December"
  [12]=>
  string(8) "December"
}
array(12) {
  [1]=>
  string(7) "January"
  [2]=>
  string(5) "March"
  [3]=>
  string(5) "March"
  [4]=>
  string(3) "May"
  [5]=>
  string(3) "May"
  [6]=>
  string(4) "July"
  [7]=>
  string(4) "July"
  [8]=>
  string(6) "August"
  [9]=>
  string(7) "October"
  [10]=>
  string(7) "October"
  [11]=>
  string(8) "December"
  [12]=>
  string(8) "December"
}


However this problem is not related to filament, it seems to be a bug with Carbon, confirmed via the Carbon SandBox:

https://play.phpsandbox.io/embed/nesbot/carbon

\Carbon\Carbon::setLocale('en');

$months = range(1, 12);

$monthNames = [];

foreach ($months as $month) {
    $monthNames[$month] = \Carbon\Carbon::now()->setMonth($month)->getTranslatedMonthName();
}

var_dump($monthNames);
\Carbon\Carbon::setLocale('en');

$months = range(1, 12);

$monthNames = [];

foreach ($months as $month) {
    $monthNames[$month] = \Carbon\Carbon::now()->setMonth($month)->getTranslatedMonthName();
}

var_dump($monthNames);


what would work is adding setDay(1).

Does anyone have any idea what causes this? Should I open a PR to add this to filament?

Carbon Issue: https://github.com/briannesbitt/Carbon/issues/3097
GitHub
Translated months names off · Issue #3097 · briannesbitt/Carbon
Hello, I encountered an issue with the following code: foreach (range(1,12) as $month) { echo \Carbon\Carbon::now()->setMonth($month)->getTranslatedMonthName() . '<br>'; } Carbo...
Translated months names off · Issue #3097 · briannesbitt/Carbon
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

related select filters
FilamentFFilament / ❓┊help
17mo ago
Problem with table filters
FilamentFFilament / ❓┊help
3y ago
SelectColumn with carbon
FilamentFFilament / ❓┊help
3y ago
Problem with Viewing Related Records in RelationManager
FilamentFFilament / ❓┊help
10mo ago