FilamentF
Filament15mo ago
nowak

How to avoid showing all widgets on all dashboard pages?

Hi, I want to create multiple dashboards, each with their own specific widgets. I have this kitchen dashboard for example:
?php

namespace App\Filament\Pages;

use App\Models\MealType;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Pages\Dashboard as BaseDashboard;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;

class KitchenDashboard extends BaseDashboard
{

  use BaseDashboard\Concerns\HasFiltersForm;

  protected static ?string $title = 'Kitchen Dashboard';
  protected static ?string $navigationIcon = 'icon-chef-hat';
  protected static string $routePath = 'kitchen';

  public function filtersForm(Form $form): Form
  {
    return $form
      ->schema([
        Section::make()
          ->schema([
            DatePicker::make('deliveryDate')
              ->formatStateUsing(fn ($state) => $state ?? now()->format('Y-m-d')),
            Select::make('mealType')
              ->options(fn() => MealType::all()
                ->sortBy('id')
                ->where('is_visible','true')
                ->pluck('name', 'id')
                ->map(function ($name) {
                  return ucfirst($name);
                })
              )
              ->default(2)
              ->selectablePlaceholder(false)
              ->native(false)
          ])
          ->columns(2),
        ]);
  }
}


This dashboard shows all my widgets in app/Filament/Widgets/, as if BaseDashboard automatically fetches and returns all existing widgets. How can I avoid this, and select which widgets should be shown on which dashboards?
Was this page helpful?