© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•14mo ago•
1 reply
Rojak

filters with relation date

iam using custom page for my report page, then i add date range filter on report page using relation data "tgl_penjualan" from other table. It work fine on Columns and DefaultSort but always error on Filters. At first it says column not found everytime i pick date, then after some tinkering it doesnt show any error when pick date but the data on table stay the same not filtered. Below is my current table code "LaporanJual.php" in App/Filament/Pages

 public static function table(Table $table): Table
   {return $table
      ->query(TransaksiKeluarItem::query()
        ->join('transaksi_keluars', 'transaksi_keluar_items.transaksi_keluar_id', '=', 'transaksi_keluars.id')
         ->select(
            'transaksi_keluars.tgl_penjualan as Tanggal', 
            'transaksi_keluar_items.id as item_id', 
            'transaksi_keluar_items.*' 
                )
            )
            ->columns([...])
            ->defaultSort('Tanggal', 'desc')
            ->filters([
                DateRangeFilter::make('Tanggal')
                ->query(function ($query) {
                    $filter = request()->all(); 
                    if (isset($filter['start']) && isset($filter['end'])) {
                        $startDate = Carbon::parse($filter['start']);
                        $endDate = Carbon::parse($filter['end'])->endOfDay(); 
                        
                        $query->whereBetween('transaksi_keluars.tgl_penjualan', [
                            $startDate,
                            $endDate,
                        ]);
                    }
                }),
            ]);
    }
 public static function table(Table $table): Table
   {return $table
      ->query(TransaksiKeluarItem::query()
        ->join('transaksi_keluars', 'transaksi_keluar_items.transaksi_keluar_id', '=', 'transaksi_keluars.id')
         ->select(
            'transaksi_keluars.tgl_penjualan as Tanggal', 
            'transaksi_keluar_items.id as item_id', 
            'transaksi_keluar_items.*' 
                )
            )
            ->columns([...])
            ->defaultSort('Tanggal', 'desc')
            ->filters([
                DateRangeFilter::make('Tanggal')
                ->query(function ($query) {
                    $filter = request()->all(); 
                    if (isset($filter['start']) && isset($filter['end'])) {
                        $startDate = Carbon::parse($filter['start']);
                        $endDate = Carbon::parse($filter['end'])->endOfDay(); 
                        
                        $query->whereBetween('transaksi_keluars.tgl_penjualan', [
                            $startDate,
                            $endDate,
                        ]);
                    }
                }),
            ]);
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Relationship Date Filters?
FilamentFFilament / ❓┊help
3y ago
relationships counting-relationships with date filters
FilamentFFilament / ❓┊help
2y ago
Chart Filters - Date picker
FilamentFFilament / ❓┊help
17mo ago