- How do I install morilog/jalali in a Laravel project?
- Run `composer require morilog/jalali:3.*` in your project directory. The package requires PHP 7.1+ and integrates directly with Laravel’s Carbon and Eloquent. No additional Laravel service provider setup is needed.
- Does this package work with Laravel’s Carbon?
- Yes, the package provides `Jalalian::fromCarbon()` for conversions and mirrors Carbon’s API where possible. You can also use Carbon macros to alias Jalali methods for seamless integration.
- What’s the difference between `jdate()` and `Jalalian::forge()`?
- `jdate()` is a helper function for quick instantiation (e.g., `jdate('last sunday')`), while `Jalalian::forge()` offers more explicit control. Both return immutable `Jalalian` objects for date manipulation.
- How do I format Jalali dates in Blade templates?
- Use the `format()` method directly: `{{ jdate()->format('%d %B %Y') }}` outputs Persian dates like `23 اسفند 1402`. For reusable formatting, create a Blade directive or Carbon macro.
- Is this package compatible with PHP 8.1+ strict typing?
- Yes, version 3.5.0 includes explicit nullable type hints (e.g., `DateTimeZone|null`) to avoid `TypeError` in strict mode. Audit your code for implicit null assumptions if upgrading from older versions.
- Can I store Jalali dates in the database?
- No, store Gregorian timestamps in the database and convert to Jalali in the presentation layer using Eloquent accessors/mutators or global scopes. The package doesn’t modify database storage strategies.
- How do I handle timezone differences with Jalali dates?
- Pass a `DateTimeZone` to `Jalalian::now()` or `fromCarbon()`. The package respects timezone settings but requires explicit handling for null timezones in strict PHP environments.
- Are there alternatives to morilog/jalali for Persian dates?
- Other options include `jalaali/jalaali-js` (JavaScript-focused) or custom implementations, but morilog/jalali is the most mature PHP/Laravel solution with Carbon integration and active maintenance.
- How do I test Jalali date conversions in Laravel?
- Use PHPUnit to test `Jalalian` methods with edge cases (e.g., invalid dates, timezones). Validate Carbon interoperability by comparing outputs with `Carbon::parse()` and `Jalalian::fromCarbon()`.
- Does this package support relative time formatting (e.g., 'ago')?
- Yes, use the `ago()` method: `jdate('now - 10 minutes')->ago()` returns `10 دقیقه پیش`. This works for both past and future dates with human-readable Persian output.