Refactor plant selection options in multiple dashboards to filter by authenticated user's plant ID.

This commit is contained in:
dhanabalan
2025-09-30 14:50:16 +05:30
parent 355ce26475
commit fad5bec0de
6 changed files with 136 additions and 112 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Pages;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Filament\Forms\Form;
@@ -35,8 +36,12 @@ class InvoiceQuantityDashboard extends Page
->statePath('filters') // Explicitly set where to store form data
->schema([
Select::make('plant')
->options(Plant::pluck('name', 'id'))
->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(['selec_plant' => $state]);