Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Buddhist Date Picker Laravel Package

zenepay/filament-buddhist-date-picker

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require zenepay/filament-buddhist-date-picker
    

    The package auto-detects Filament 4 and registers the extension.

  2. First Use Case: Replace a standard DatePicker with Buddhist-era support:

    use Filament\Forms\Components\DatePicker;
    
    DatePicker::make('birth_date')
        ->label('Birth Date (Buddhist Era)')
        ->buddhist(); // Enable Buddhist era
    
    • The picker now displays years in the Buddhist calendar (e.g., 2565 instead of 2022).
    • Input/output remains in Gregorian format (default Laravel behavior) unless configured otherwise.
  3. Where to Look First:

    • Filament Docs on DatePicker
    • Package README for version-specific notes.
    • Check resources/views/vendor/filament/forms/components/date-picker.blade.php if customizing templates.

Implementation Patterns

Core Workflows

  1. Basic Integration:

    // Form builder
    DatePicker::make('event_date')
        ->buddhist()
        ->required()
        ->maxDate(now()->addYears(10));
    
    • Key Methods:
      • buddhist(): Toggle Buddhist era (default: false).
      • buddhistEraLabel(): Customize the era label (e.g., "BE" → "Buddhist Era").
      • convertToGregorian(): Force output in Gregorian format (useful for storage).
  2. Dynamic Era Switching:

    DatePicker::make('custom_date')
        ->buddhist(fn ($get) => $get('use_buddhist_era'))
        ->rules(['required', 'date']);
    
    • Use a closure to conditionally enable Buddhist era based on form state.
  3. DateTimePicker:

    DateTimePicker::make('scheduled_at')
        ->buddhist()
        ->timezone('Asia/Bangkok');
    
    • Supports all DateTimePicker features (time zones, seconds, etc.) with Buddhist-era years.
  4. Table Columns:

    use Filament\Tables\Columns\DateColumn;
    
    DateColumn::make('created_at')
        ->dateFormat('Y-m-d')
        ->buddhist(); // Display Buddhist era in tables
    
    • Extends DateColumn for consistent Buddhist-era display in lists.
  5. Validation & Storage:

    • Input Handling: The package converts Buddhist-era input to Gregorian for validation/storage by default.
    • Output Formatting: Use ->formatStateUsing() to display Buddhist-era dates in views:
      ->formatStateUsing(fn ($state) => Carbon::parse($state)->buddhistYear)
      

Integration Tips

  • Localization: Works with Filament’s built-in localization. Test with app()->setLocale('th') for Thai-specific formatting.
  • API Responses: Ensure API responses use Gregorian dates for consistency:
    return $record->toArray(['created_at' => fn ($date) => $date->format('Y-m-d')]);
    
  • Database Storage: Store dates as Gregorian timestamps (default) unless your app explicitly uses Buddhist-era calculations.

Gotchas and Tips

Pitfalls

  1. Double Conversion:

    • Issue: If you manually convert Gregorian ↔ Buddhist in code and use buddhist(), dates may misalign.
    • Fix: Stick to one system (prefer Gregorian for storage, Buddhist for display).
  2. Time Zone Confusion:

    • Issue: Buddhist-era calculations are timezone-agnostic. Ensure DateTimePicker uses the correct timezone:
      ->timezone('Asia/Bangkok') // Critical for accurate display
      
    • Fix: Set a default timezone in config/app.php if not specified.
  3. Validation Quirks:

    • Issue: Custom validation rules (e.g., after:yesterday) may fail if Buddhist-era dates are not converted.
    • Fix: Use ->convertToGregorian() or manually parse:
      ->rules(['after:yesterday', fn ($attribute, $value, $fail) => ...])
      
  4. Template Overrides:

    • Issue: Custom Blade templates for DatePicker may break Buddhist-era rendering.
    • Fix: Extend the default view:
      @php
          $isBuddhist = $get('buddhist') ?? false;
      @endphp
      <x-filament::input
          x-data="{
              ...
          }"
          x-bind:buddhist-era="{{ $isBuddhist }}"
      >
      

Debugging

  • Check Input/Output:
    dd($record->birth_date->copy()->setToStringFormat('Y-m-d (BE: Y)'));
    
  • Log Era Calculations:
    \Log::debug('Buddhist Year:', [
        'input' => $date->year,
        'gregorian' => $date->copy()->subYears(543)->year,
    ]);
    
    (Note: 543 = years between 2022 and 2565 BE.)

Extension Points

  1. Custom Era Labels:
    DatePicker::make('date')
        ->buddhist()
        ->buddhistEraLabel('BE'); // Override "Buddhist Era" → "BE"
    
  2. Add Era to API Responses:
    $resource->appendToArrayRepresentation(function ($record) {
        return [
            'birth_date_buddhist' => $record->birth_date->copy()->addYears(543)->format('Y-m-d'),
        ];
    });
    
  3. Global Configuration:
    // config/filament.php
    'components' => [
        'date_picker' => [
            'default_buddhist' => env('FILAMENT_BUDDHIST_DEFAULT', false),
        ],
    ];
    
    (Note: Requires custom package extension.)

Performance

  • Avoid Redundant Conversions: Cache converted dates if used frequently:
    protected static function cacheKey($value): string {
        return 'buddhist_'.$value->format('Y-m-d');
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle