Refactor plant selection options by authenticated user's plant ID.

This commit is contained in:
dhanabalan
2025-09-29 18:26:35 +05:30
parent ece893ae84
commit 85ebccd22c
8 changed files with 50 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Filament\Pages;
use App\Filament\Widgets\GuardPatrolDayChart;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Forms\Form;
@@ -34,13 +35,17 @@ class GuardPatrolDayCount extends Page
->statePath('filters')
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->label('Select Plant')
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_plant' => $state]);
$this->dispatch('patrolEntryChart');
}),
->label('Select Plant')
// ->options(Plant::pluck('name', 'id'))
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state) {
session(['selected_plant' => $state]);
$this->dispatch('patrolEntryChart');
}),
]);
}