1
0
forked from poc/pds

Refactor plant selection logic to filter by user-specific plant ID in various resources

This commit is contained in:
dhanabalan
2025-10-08 18:22:22 +05:30
parent 98dc59538f
commit 5e48861589
6 changed files with 35 additions and 7 deletions

View File

@@ -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()

View File

@@ -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 () {

View File

@@ -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 () {

View File

@@ -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),

View File

@@ -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 () {

View File

@@ -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 () {