Laravel Packagev7.xMIT License39.7K+ downloads

Hijri: Every date, in the Hijri calendar

Hijri dates in Laravel, zero setup. Call toHijri() on any Carbon date, convert back with fromHijri(), and print 1 Ramadan 1445 with @hijri.

$composer require pharaonic/laravel-hijri
Key Features

Everything you need for Hijri dates in Laravel

Install it and every Carbon date already speaks Hijri, with no setup code.

Carbon Mixin

Call toHijri() on now(), Eloquent dates or any Carbon instance.

Hijri to Gregorian

Carbon::fromHijri() and Carbon::parseHijri() give you a Gregorian date to store.

Blade Directive

@hijri($date) prints a localized Hijri date in your default format.

Validation Rule

HijriDateRule rejects impossible dates like 1445-02-30, with English and Arabic messages.

Day Adjustment

Match local moon sighting with HIJRI_ADJUSTMENT, or per call.

Arabic Month Names

Arabic locales get رَمضان, every other locale gets Ramadan.

A quick look

Convert both ways with Carbon, then print the result in Blade.

routes/web.php
1use Carbon\Carbon;
2 
3Route::get('/today', function () {
4 $hijri = Carbon::parse('2024-03-11')->toHijri(); // Pharaonic\Hijri\Hijri
5 
6 $hijri->format('Y-m-d'); // "1445-09-01"
7 $hijri->locale('ar')->isoFormat('D MMMM YYYY'); // "1 رَمضان 1445"
8 
9 $eid = Carbon::fromHijri($hijri->year, 10, 1); // Gregorian Carbon date
10 
11 return view('today', compact('eid')); // @hijri($eid) in the view
12});
FAQ

Hijri Questions

Quick answers about installing and using Hijri.

What is Hijri?

Hijri dates for Laravel. Convert Carbon dates both ways, print them with @hijri, and validate Hijri input. It's a free, open-source Laravel package by Pharaonic.

How do I install Hijri?

Run composer require pharaonic/laravel-hijri in your project's root directory.

What does Hijri require?

The latest release requires PHP 8.0+ and Laravel 7.

Is Hijri free to use?

Yes. Hijri is open source under the MIT license, so you can use it in personal and commercial projects.

Why is the Hijri date one day off from my local calendar?

The package uses the tabular Hijri calendar, while official month starts depend on moon sighting. Set HIJRI_ADJUSTMENT in your .env (the default is -1), or pass an adjustment to a single call like toHijri(0).

Should I store Hijri dates in the database?

No. Store dates as Gregorian, so sorting, queries and date math keep working, and convert to Hijri when you display them. Use Carbon::parseHijri() to turn Hijri input into a Gregorian date before saving.

How do I show Arabic month names?

Set the locale to Arabic: $date->toHijri()->locale('ar'). The @hijri Blade directive follows your app locale, or accepts a locale as its third argument.

How do I validate a Hijri date from a form?

Add new HijriDateRule() to your rules. It accepts YYYY-MM-DD with an optional time and rejects dates that don't exist in the Hijri calendar.

Where can I find the Hijri documentation?

Read the Hijri documentation for setup, configuration, and usage examples.

How do I report a bug or contribute to Hijri?

Open an issue or a pull request on GitHub, or ask in the Pharaonic Discord.

Ready to dig in?

Read the full documentation for installation, the day adjustment config, Carbon conversion methods, the @hijri Blade directive, Hijri date validation, Arabic and English localization, and real-world examples.