danialzash/laravel-jalali
Composer 安装命令:
composer require danialzash/laravel-jalali
包简介
Laravel helpers for Jalali (Shamsi) date formatting
README 文档
README
A Laravel package that provides seamless Jalali (Shamsi/Persian) date formatting with Carbon integration.
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
Installation
Install the package via Composer:
composer require danialzash/laravel-jalali
The package will auto-register its service provider and facade.
Publish Configuration (Optional)
php artisan vendor:publish --tag=jalali-config
This will create a config/jalali.php file where you can set the default date format:
return [ 'default_format' => 'datetime', // Options: 'datetime', 'date', 'time', or custom format ];
Usage
Using the Helper Function
The simplest way to convert dates to Jalali:
// Current date/time in Jalali jalali(); // Convert a specific date jalali('2024-03-20'); // With custom format jalali(now(), 'Y/m/d'); // From a Carbon instance jalali($user->created_at, 'l j F Y');
Using the Facade
use Danialzash\LaravelJalali\Facades\Jalali; // Get a Jalalian instance $jalaliDate = Jalali::from(now()); // Format directly $formatted = Jalali::format(now(), 'Y-m-d H:i:s');
Using Carbon Macros
The package adds two macros to Laravel's Carbon class:
use Illuminate\Support\Carbon; // Get a Jalalian instance from Carbon $jalali = Carbon::now()->toJalali(); // Get a formatted Jalali string directly $dateString = Carbon::now()->toJalaliString('Y/m/d'); // Works with any Carbon instance $user->created_at->toJalaliString(); // e.g., "1402/12/30 14:30:00"
Working with Jalalian
The toJalali() method returns a Morilog\Jalali\Jalalian instance, giving you access to all its methods:
$jalali = now()->toJalali(); $jalali->getYear(); // 1402 $jalali->getMonth(); // 12 $jalali->getDay(); // 30 $jalali->format('l j F'); // پنجشنبه 30 اسفند $jalali->ago(); // 2 ساعت پیش
Format Characters
Common format characters (from morilog/jalali):
| Character | Description | Example |
|---|---|---|
Y |
Full year | 1402 |
y |
Two-digit year | 02 |
m |
Month (zero-padded) | 01-12 |
n |
Month | 1-12 |
d |
Day (zero-padded) | 01-31 |
j |
Day | 1-31 |
H |
Hour (24-hour, zero-padded) | 00-23 |
i |
Minutes (zero-padded) | 00-59 |
s |
Seconds (zero-padded) | 00-59 |
F |
Full month name | فروردین |
l |
Full day name | شنبه |
D |
Short day name | ش |
Examples
// In a Blade template <p>تاریخ ثبتنام: {{ $user->created_at->toJalaliString('Y/m/d') }}</p> // In a controller public function show(User $user) { return [ 'name' => $user->name, 'joined' => jalali($user->created_at, 'j F Y'), ]; } // With Eloquent $posts = Post::latest()->get()->map(fn ($post) => [ 'title' => $post->title, 'date' => $post->created_at->toJalaliString('Y/m/d'), ]);
Testing
composer test
Credits
- Danial Zash
- morilog/jalali - The underlying Jalali date library
License
The MIT License (MIT). Please see License File for more information.
danialzash/laravel-jalali 适用场景与选型建议
danialzash/laravel-jalali 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 danialzash/laravel-jalali 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 danialzash/laravel-jalali 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-08