Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

auroralabs's avatar

Filament tabs Filter Question

Hi I have a filament resource that has tabs filter to select a specific status from the Receipts table.

My question is is it possible to either have 2 sets of tabs or a condition where a Warehouse location can be filtered first before the filtering the status of the receipt.

<?php

namespace App\Filament\Resources\ReceiptResource\Pages;

use App\Filament\Resources\ReceiptResource;
use App\Models\Receipt;
use App\Models\ReceiptStatus;
use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListReceipts extends ListRecords
{
    protected static string $resource = ReceiptResource::class;

    public function getTabs(): array
    {
        return [
            'all' => Tab::make('All Receipts')
                ->badge(Receipt::count()),

            'goods_inwards' => Tab::make('Goods Inwards')
                ->query(fn (Builder $query) => $query->where('receipt_status_id', ReceiptStatus::where('name', 'Goods Inwards')->first()->id))
                ->badge(Receipt::where('receipt_status_id', ReceiptStatus::where('name', 'Goods Inwards')->first()->id)->count()),

            'gi_processing' => Tab::make('GI Processing')
                ->query(fn (Builder $query) => $query->where('receipt_status_id', ReceiptStatus::where('name', 'GI Processing')->first()->id))
                ->badge(Receipt::where('receipt_status_id', ReceiptStatus::where('name', 'GI Processing')->first()->id)->count()),

            'corrective_action' => Tab::make('Corrective Action')
                ->query(fn (Builder $query) => $query->where('receipt_status_id', ReceiptStatus::where('name', 'Corrective Action')->first()->id))
                ->badge(Receipt::where('receipt_status_id', ReceiptStatus::where('name', 'Corrective Action')->first()->id)->count()),

            'archive' => Tab::make('Archive')
                ->query(fn (Builder $query) => $query->onlyTrashed())
                ->badge(Receipt::onlyTrashed()->count()),
        ];
    }
    protected function getHeaderActions(): array
    {
        return [
            Actions\CreateAction::make(),
        ];
    }
}

'location_aberdeen' => Tab::make('Aberdeen')
    ->query(fn (Builder $query) => $query->where('warehouse_id', Warehouse::where('name', 'Aberdeen')->first()->id))
    ->badge(Receipt::where('warehouse_id', Warehouse::where('name', 'Aberdeen')->first()->id)->count()),

'location_edinburgh' => Tab::make('Edinburgh')
    ->query(fn (Builder $query) => $query->where('warehouse_id', Warehouse::where('name', 'Edinburgh')->first()->id))
    ->badge(Receipt::where('warehouse_id', Warehouse::where('name', 'Edinburgh')->first()->id)->count()),
    
'location_glasgow' => Tab::make('Glasgow')
    ->query(fn (Builder $query) => $query->where('warehouse_id', Warehouse::where('name', 'Glasgow')->first()->id))
    ->badge(Receipt::where('warehouse_id', Warehouse::where('name', 'Glasgow')->first()->id)->count()),

0 likes
1 reply
LaryAI's avatar
Level 58

To achieve the desired functionality of filtering by warehouse location first and then by receipt status, you can use a combination of dropdown filters and tabs. Here's a step-by-step solution:

  1. Add a Dropdown Filter for Warehouse Locations: This will allow users to select a warehouse location first.
  2. Modify the Tabs to Respect the Selected Warehouse Location: The tabs will then filter the receipts based on both the selected warehouse location and the receipt status.

Here's how you can implement this:

Step 1: Add a Dropdown Filter for Warehouse Locations

First, add a dropdown filter for warehouse locations in your ListReceipts class.

Explanation:

  1. Dropdown Filter: The getFilters method adds a dropdown filter for selecting a warehouse. The SelectFilter is used to create the dropdown, and the query method is used to filter the receipts based on the selected warehouse.

  2. Tabs with Conditional Queries: The getTabs method is modified to respect the selected warehouse location. The when method is used to conditionally apply the warehouse filter to each tab's query.

This way, users can first select a warehouse location from the dropdown filter, and then the tabs will filter the receipts based on both the selected warehouse location and the receipt status.

Please or to participate in this conversation.