Refactor plant selection logic in InvoiceValidationResource to improve readability and maintainability

This commit is contained in:
dhanabalan
2025-11-07 15:21:20 +05:30
parent 4ac8dde11e
commit 6770aaa25a

View File

@@ -306,20 +306,20 @@ 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(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 () {
return optional(InvoiceValidation::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('invoice_serial_number', null);
})
->reactive(),
// ->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 () {
return optional(InvoiceValidation::latest()->first())->plant_id;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('invoice_serial_number', null);
})
->reactive(),
FileUpload::make('invoice_serial_number')
->label('Invoice Serial Number')