Refactor plant selection options across multiple resources to display plants based on the authenticated user's plant ID, ensuring users only see relevant options.
This commit is contained in:
@@ -36,7 +36,10 @@ class AlertMailRuleResource extends Resource
|
||||
Forms\Components\Select::make('plant')
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->options(fn () => 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(fn ($get) => ! $get('is_active'))
|
||||
->afterStateUpdated(fn ($state, callable $set) => $state ? $set('is_active', false) : null),
|
||||
// ->options(fn () => Plant::pluck('id', 'name')->toArray()),
|
||||
@@ -46,14 +49,16 @@ class AlertMailRuleResource extends Resource
|
||||
->options([
|
||||
'InvoiceValidation' => 'InvoiceValidation',
|
||||
'ProductionQuantities' => 'ProductionQuantities',
|
||||
//'Calibration' => 'Calibration',
|
||||
]),
|
||||
Forms\Components\Select::make('rule_name')
|
||||
->label('Rule Name')
|
||||
->options([
|
||||
->options([
|
||||
'InvoiceMail' => 'Invoice Mail',
|
||||
'SerialInvoiceMail' => 'Serial Invoice Mail',
|
||||
'MaterialInvoiceMail' => 'Material Invoice Mail',
|
||||
'ProductionMail' => 'Production Mail',
|
||||
//'CalibrationMail' => 'Calibration Mail',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
|
||||
Reference in New Issue
Block a user