You can use the translatedFormat method:
protected function jobPublishingDateFrom(): Attribute
{
return new Attribute(
get: fn ($value) => (Carbon::parse($value)->translatedFormat('d.F Y'),
);
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi Everybody,
i am trying to return a date from my database with the new accessor syntax
protected function jobPublishingDateFrom(): Attribute { return new Attribute( get: fn ($value) => (Carbon::parse($value))->format('d.F Y'), ); }
In the config/app.php the Timezone is configured to 'Europe/Berlin' and the APP_LOCALE=de but the name of the day is everytime in english. I tried to set ->locale('de') for carbon manually but nothing changed.
Casting like this also all the time english:
protected $casts = [ 'job_publishing_date_from' => 'datetime:d.F Y' ];
Any Ideas?
You can use the translatedFormat method:
protected function jobPublishingDateFrom(): Attribute
{
return new Attribute(
get: fn ($value) => (Carbon::parse($value)->translatedFormat('d.F Y'),
);
}
Please or to participate in this conversation.