# Navigation Badge Implementation Guide
This guide shows how to add counters (badges) to each resource in the Filament navigation.
## How to Add Badges to Resources
Add these two methods to any Resource class to display a counter badge:
### Method 1: Simple Count Badge
```php
public static function getNavigationBadge(): ?string
{
return static::$model::count();
}
```
### Method 2: Count with Color Based on Threshold
```php
public static function getNavigationBadge(): ?string
{
return static::$model::count();
}
public static function getNavigationBadgeColor(): string|array|null
{
$count = static::$model::count();
if ($count > 100) {
return 'danger'; // Red for high numbers
} elseif ($count > 50) {
return 'warning'; // Yellow/Orange for medium numbers
}
return 'success'; // Green for low numbers
}
```
### Method 3: Custom Badge with Conditions
```php
public static function getNavigationBadge(): ?string
{
// Show only active records
return static::$model::where('is_active', true)->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
return 'primary'; // Blue
}
```
### Method 4: Badge with Tooltip
```php
public static function getNavigationBadge(): ?string
{
return static::$model::count();
}
public static function getNavigationBadgeTooltip(): ?string
{
$count = static::$model::count();
return "Total: {$count} records";
}
```
## Available Badge Colors
- `primary` - Blue
- `success` - Green
- `warning` - Yellow/Orange
- `danger` - Red
- `info` - Light Blue
- `gray` - Gray
## Examples for Different Resources
### BookingResource.php
```php
public static function getNavigationBadge(): ?string
{
return static::$model::whereDate('check_in', '>=', now())->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
return 'primary';
}
public static function getNavigationBadgeTooltip(): ?string
{
return 'Upcoming bookings';
}
```
### ClientResource.php
```php
public static function getNavigationBadge(): ?string
{
return static::$model::count();
}
public static function getNavigationBadgeColor(): string|array|null
{
$count = static::$model::count();
return $count > 1000 ? 'success' : 'primary';
}
```
### InvoiceResource.php
```php
public static function getNavigationBadge(): ?string
{
// Show unpaid invoices
return static::$model::where('status', 'unpaid')->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
$unpaid = static::$model::where('status', 'unpaid')->count();
return $unpaid > 10 ? 'danger' : 'warning';
}
public static function getNavigationBadgeTooltip(): ?string
{
return 'Unpaid invoices';
}
```
### VenueResource.php
```php
public static function getNavigationBadge(): ?string
{
return static::$model::where('is_active', true)->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
return 'success';
}
public static function getNavigationBadgeTooltip(): ?string
{
return 'Active venues';
}
```
### ReservationResource.php
```php
public static function getNavigationBadge(): ?string
{
// Today's reservations
return static::$model::whereDate('reservation_date', today())->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
$count = static::$model::whereDate('reservation_date', today())->count();
if ($count > 20) {
return 'danger';
} elseif ($count > 10) {
return 'warning';
}
return 'success';
}
public static function getNavigationBadgeTooltip(): ?string
{
return "Today's reservations";
}
```
### UserResource.php
```php
public static function getNavigationBadge(): ?string
{
// Show only active users
return static::$model::where('is_active', true)->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
return 'primary';
}
```
### ProductResource.php
```php
public static function getNavigationBadge(): ?string
{
// Show low stock products
return static::$model::where('quantity', '<', 10)->count();
}
public static function getNavigationBadgeColor(): string|array|null
{
$lowStock = static::$model::where('quantity', '<', 10)->count();
return $lowStock > 0 ? 'danger' : 'success';
}
public static function getNavigationBadgeTooltip(): ?string
{
return 'Low stock items';
}
```
## Performance Considerations
For large databases, consider caching the badge counts:
```php
public static function getNavigationBadge(): ?string
{
return Cache::remember(
'navigation.badge.' . static::class,
now()->addMinutes(5),
fn() => static::$model::count()
);
}
```
## Quick Implementation Checklist
For each resource you want to add a badge to:
1. ✅ Add `getNavigationBadge()` method
2. ✅ Add `getNavigationBadgeColor()` method (optional but recommended)
3. ✅ Add `getNavigationBadgeTooltip()` method (optional)
4. ✅ Test the badge appears in navigation
5. ✅ Verify the count is accurate
6. ✅ Check performance with large datasets
## Resources That Should Have Badges
### High Priority (Core Business)
- ✅ BookingResource - Show upcoming/today's bookings
- ✅ ReservationResource - Show active reservations
- ✅ ClientResource - Show total clients
- ✅ VenueResource - Show active venues
- ✅ InvoiceResource - Show unpaid invoices
- ✅ PaymentTransactionResource - Show pending payments
### Medium Priority
- ✅ ProductResource - Show low stock items
- ✅ ServiceResource - Show active services
- ✅ UserResource - Show active users
- ✅ OperatorResource - Show active operators
- ✅ ReviewResource - Show pending reviews
### Lower Priority
- VenueSpotResource
- VenueObjectResource
- GalleryResource
- WorkspaceResource
- etc.