Skip to content

Commit

Permalink
Customers by Stage: Tabs with Numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
tqt97 committed Oct 15, 2023
1 parent 93410a5 commit 69b0ebe
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app/Filament/Resources/CustomerResource/Pages/ListCustomers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Filament\Resources\CustomerResource\Pages;

use App\Filament\Resources\CustomerResource;
use App\Models\Customer;
use App\Models\PipelineStage;
use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;

class ListCustomers extends ListRecords
Expand All @@ -16,4 +19,32 @@ protected function getHeaderActions(): array
Actions\CreateAction::make(),
];
}

public function getTabs(): array
{
$tabs = [];

// Adding `all` as our first tab
$tabs['all'] = Tab::make('All Customers')
// We will add a badge to show how many customers are in this tab
->badge(Customer::count());

// Load all Pipeline Stages
$pipelineStages = PipelineStage::orderBy('position')->withCount('customers')->get();

// Loop through each Pipeline Stage
foreach ($pipelineStages as $pipelineStage) {
// Add a tab for each Pipeline Stage
// Array index is going to be used in the URL as a slug, so we transform the name into a slug
$tabs[str($pipelineStage->name)->slug()->toString()] = Tab::make($pipelineStage->name)
// We will add a badge to show how many customers are in this tab
->badge($pipelineStage->customers_count)
// We will modify the query to only show customers in this Pipeline Stage
->modifyQueryUsing(function ($query) use ($pipelineStage) {
return $query->where('pipeline_stage_id', $pipelineStage->id);
});
}

return $tabs;
}
}

0 comments on commit 69b0ebe

Please sign in to comment.