diff --git a/app/Filament/Resources/GuardPatrolEntryResource.php b/app/Filament/Resources/GuardPatrolEntryResource.php index a9acdd9..7d0a258 100644 --- a/app/Filament/Resources/GuardPatrolEntryResource.php +++ b/app/Filament/Resources/GuardPatrolEntryResource.php @@ -419,7 +419,11 @@ class GuardPatrolEntryResource extends Resource ->label('Import Guard Patrol Entries') ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) + // ->options(Plant::pluck('name', 'id')->toArray()) + ->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(); + }) ->label('Select Plant') ->reactive() ->required() diff --git a/app/Filament/Resources/InvoiceValidationResource.php b/app/Filament/Resources/InvoiceValidationResource.php index 1efe6e9..80a54d6 100644 --- a/app/Filament/Resources/InvoiceValidationResource.php +++ b/app/Filament/Resources/InvoiceValidationResource.php @@ -306,7 +306,11 @@ class InvoiceValidationResource extends Resource ->label('Import Serial Invoice') ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + ->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(); + }) ->label('Select Plant') ->required() ->default(function () { @@ -623,7 +627,11 @@ class InvoiceValidationResource extends Resource ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + ->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(); + }) ->label('Select Plant') ->required() ->default(function () { diff --git a/app/Filament/Resources/LocatorInvoiceValidationResource.php b/app/Filament/Resources/LocatorInvoiceValidationResource.php index fee783e..69943ff 100644 --- a/app/Filament/Resources/LocatorInvoiceValidationResource.php +++ b/app/Filament/Resources/LocatorInvoiceValidationResource.php @@ -501,7 +501,11 @@ class LocatorInvoiceValidationResource extends Resource ->label('Import Invoice') ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) + // ->options(Plant::pluck('name', 'id')->toArray()) + ->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(); + }) ->label('Select Plant') ->required() ->default(function () { diff --git a/app/Filament/Resources/PalletValidationResource.php b/app/Filament/Resources/PalletValidationResource.php index 2d58c32..45ade22 100644 --- a/app/Filament/Resources/PalletValidationResource.php +++ b/app/Filament/Resources/PalletValidationResource.php @@ -514,7 +514,11 @@ class PalletValidationResource extends Resource ->schema([ Forms\Components\Select::make('plant') ->label('Select Plant') - ->options(Plant::pluck('name', 'id')->toArray()) + // ->options(Plant::pluck('name', 'id')->toArray()) + ->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(); + }) ->required() ->reactive() ->columnSpan(2), diff --git a/app/Filament/Resources/SerialValidationResource.php b/app/Filament/Resources/SerialValidationResource.php index 19d180b..9d9f2fb 100644 --- a/app/Filament/Resources/SerialValidationResource.php +++ b/app/Filament/Resources/SerialValidationResource.php @@ -285,7 +285,11 @@ class SerialValidationResource extends Resource ->label('Import Serial Invoice') ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + // ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs + ->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(); + }) ->label('Select Plant') ->required() ->default(function () { diff --git a/app/Filament/Resources/WeightValidationResource.php b/app/Filament/Resources/WeightValidationResource.php index 5c2da03..881827a 100644 --- a/app/Filament/Resources/WeightValidationResource.php +++ b/app/Filament/Resources/WeightValidationResource.php @@ -380,7 +380,11 @@ class WeightValidationResource extends Resource ->label('Import OBD Weight Invoice') ->form([ Select::make('plant_id') - ->options(Plant::pluck('name', 'id')->toArray()) + // ->options(Plant::pluck('name', 'id')->toArray()) + ->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(); + }) ->label('Select Plant') ->required() ->default(function () {