Search by

pitchayakit / laravel-buddhist-era

pitchayakit

Laravel package that makes Carbon's translatedFormat() show the Buddhist Era year (CE + 543) in Thai and the Gregorian year in every other locale.

Package info

github.com/pitchayakit/laravel-buddhist-era

pkg:composer/pitchayakit/laravel-buddhist-era

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-14 11:26 UTC

This package is auto-updated.

Last update: 2026-11-14 11:30:48 UTC


README

A Laravel package that makes Carbon's translatedFormat() show the Buddhist Era year (CE + 543) when the locale is Thai, and the Gregorian year in every other locale. Built for Laravel apps that serve more than one language.

Requires Laravel 12 or 13. It does not work with Carbon outside Laravel.

Install

composer require pitchayakit/laravel-buddhist-era

That is all. Laravel discovers the package's service provider, so there is nothing to register or configure.

Use

Nothing changes at the call site:

$model->created_at->translatedFormat('d M Y');     // th: 14 พ.ย. 2569   en: 14 Nov 2026
$model->created_at->translatedFormat('l j F Y');   // th: เสาร์ 14 พฤศจิกายน 2569
$model->created_at->format('Y-m-d');               // 2026-11-14 in every locale
  • The date follows the app locale, so there is no need to check app()->getLocale() or call ->locale().
  • Y, y and o are converted in Thai; an escaped \Y stays literal.
  • Only the year is converted. The date is never shifted, so leap days and weekdays stay correct.
  • format() is untouched, so database values and machine formats stay Gregorian.

Which dates are covered

The package makes Laravel create its date class wherever it builds a date: model date casts, now(), today() and the Date facade.

A date built with Carbon::parse() or Carbon::now() directly is a plain Carbon and stays Gregorian. Use Date::parse() instead.

Livewire is supported: the package registers the class with Livewire so dates in public properties survive between requests.

If your app already sets its own date class with Date::use(), that choice wins and this package stays inactive.