mokhosh / filament-jalali
Add Jalali datetime to your filament tables
Installs: 7 464
Dependents: 1
Suggesters: 0
Security: 0
Stars: 30
Watchers: 1
Forks: 2
Open Issues: 2
Language:JavaScript
Requires
- php: ^8.1
- filament/filament: ^3.0
- illuminate/contracts: ^10.0|^11.0
- morilog/jalali: ^v3.4.2
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9|^8.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
No fuss package to add Jalali Date and DateTime columns to your table, and a beautiful Jalali Date and DateTime picker to your forms.
No new column type, just keep using your good old TextColumn
s!
No new form components, just keep using your beautiful DatePicker
s and DateTimePicker
s!
Installation
You can install the package via composer:
composer require mokhosh/filament-jalali
Usage
To add Jalali date and date-time columns to your tables, just add jalaliDate
and jalaliDateTime
to the filament TextColumn
s instead of date
or dateTime
.
// Yes! Just use Filament's original TextColumns! use Filament\Tables; Tables\Columns\TextColumn::make('created_at') ->jalaliDate(), Tables\Columns\TextColumn::make('updated_at') ->jalaliDateTime(),
To add Jalali date and date-time columns to your infolists, just add jalaliDate
and jalaliDateTime
to the filament TextEntry
s instead of date
or dateTime
.
use Filament\Infolists\Components; Components\TextEntry::make('created_at') ->jalaliDate(), Components\TextEntry::make('updated_at') ->jalaliDateTime(),
To add Jalali date and date-time pickers to your forms, just add jalali
to your DatePicker
and DateTimePicker
.
// Yes! Just use Filament's original DatePickers and DateTimePickers! use Filament\Forms; Forms\Components\DatePicker::make('moderated_at') ->jalali(), Forms\Components\DateTimePicker::make('published_at') ->jalali(),
Ignoring Jalali Conversion
If you want to ignore jalali conversion you can use the when
and unless
methods:
use Filament\Tables; use Filament\Infolists\Components; use Filament\Forms; use Illuminate\Support\Facades\App; Tables\Columns\TextColumn::make('created_at') ->date() ->when(App::isLocale('fa'), fn (TextColumn $column) => $column->jalaliDate()), Components\TextEntry::make('updated_at') ->dateTime() ->unless(App::isLocale('en'), fn (TextColumn $column) => $column->jalaliDateTime()), Forms\Components\DatePicker::make('birthday') ->when(App::isLocale('fa'), fn (TextColumn $column) => $column->jalali()),
Configuring the Format Globally
You can set the default date formats for tables and infolists anywhere you want, likely in a service provider:
public function boot(): void { Table::$defaultDateDisplayFormat = 'Y/m/d'; Table::$defaultDateTimeDisplayFormat = 'Y/m/d H:i:s'; Infolist::$defaultDateDisplayFormat = 'Y/m/d'; Infolist::$defaultDateTimeDisplayFormat = 'Y/m/d H:i:s'; }
Some common formats you might want to use:
j F Y
۱۵ مهر ۱۳۶۸
Y/m/d
۱۳۶۸/۰۷/۱۵
l j F
شنبه ۱۵ مهر
Credits
License
The MIT License (MIT). Please see License File for more information.