1
0
forked from poc/pds
Files
poc-pds1/app/Filament/Pages/Dashboard.php
2025-03-28 16:52:40 +05:30

51 lines
1.8 KiB
PHP

<?php
namespace App\Filament\Pages;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Tables\Filters\SelectFilter;
use Illuminate\Support\Facades\DB;
use App\Models\Plant;
class Dashboard extends \Filament\Pages\Dashboard
{
use HasFiltersForm;
public function filtersForm(Form $form): Form
{
$selectedPlant = session('selected_plant', request()->input('filters.Plant'));
return $form->schema([
// Plant Filter
Select::make('Plant')
->options(Plant::pluck('name', 'id')) // Fetch plant names with their IDs
->label('Select Plant')
->reactive()
->afterStateUpdated(function ($state, callable $set) use ($selectedPlant) {
// Update only in memory and not in the URL
session(['selected_plant' => $state]); // Store in session
session()->forget('selected_line'); // Reset line filter
$set('Plant', $state);
$set('Line', null);
$this->dispatch('filtersUpdated'); // Notify chart to refresh
}),
// Line Filter
Select::make('Line')
->options(function ($get) {
$plantId = $get('Plant');
return $plantId ? Plant::find($plantId)->getLineNames()->pluck('name', 'id') : [];
})
->label('Select Line')
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_line' => $state]); // Store in session
$this->dispatch('filtersUpdated'); // Notify chart to refresh
}),
]);
}
}