Refactor plant selection logic in InvoiceValidationResource to improve readability and maintainability
This commit is contained in:
@@ -306,20 +306,20 @@ class InvoiceValidationResource extends Resource
|
|||||||
->label('Import Serial Invoice')
|
->label('Import Serial Invoice')
|
||||||
->form([
|
->form([
|
||||||
Select::make('plant_id')
|
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) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
->label('Select Plant')
|
->label('Select Plant')
|
||||||
->required()
|
->required()
|
||||||
->default(function () {
|
->default(function () {
|
||||||
return optional(InvoiceValidation::latest()->first())->plant_id;
|
return optional(InvoiceValidation::latest()->first())->plant_id;
|
||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('invoice_serial_number', null);
|
$set('invoice_serial_number', null);
|
||||||
})
|
})
|
||||||
->reactive(),
|
->reactive(),
|
||||||
|
|
||||||
FileUpload::make('invoice_serial_number')
|
FileUpload::make('invoice_serial_number')
|
||||||
->label('Invoice Serial Number')
|
->label('Invoice Serial Number')
|
||||||
|
|||||||
Reference in New Issue
Block a user