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:
@@ -65,8 +65,12 @@ class ProductionQuantityResource extends Resource
|
||||
->required()
|
||||
// ->nullable()
|
||||
->reactive()
|
||||
// ->statePath('filters')
|
||||
// ->statePath('filters')
|
||||
->columnSpan(2) //1
|
||||
->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();
|
||||
})
|
||||
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
|
||||
->default(function () {
|
||||
return optional(ProductionQuantity::latest()->first())->plant_id;
|
||||
@@ -96,8 +100,6 @@ class ProductionQuantityResource extends Resource
|
||||
// }
|
||||
// ",
|
||||
// ])
|
||||
|
||||
|
||||
// ->extraAttributes([
|
||||
// 'x-on:change' => "\$wire.dispatch('filtersUpdated', { plantId: \$event.target.value })"
|
||||
// ])
|
||||
@@ -112,10 +114,6 @@ class ProductionQuantityResource extends Resource
|
||||
// ->extraAttributes([
|
||||
// 'x-on:change' => '$dispatch("plant-updated", { plantId: $event.target.value }); console.log("Plant updated:", $event.target.value);',
|
||||
// ])
|
||||
|
||||
|
||||
|
||||
|
||||
// ->extraAttributes([
|
||||
// 'x-data' => '{ value: "" }',
|
||||
// 'x-model' => 'value',
|
||||
@@ -123,7 +121,6 @@ class ProductionQuantityResource extends Resource
|
||||
// ])
|
||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
|
||||
Forms\Components\Select::make('block_name')
|
||||
->label('Block')
|
||||
->required()
|
||||
|
||||
Reference in New Issue
Block a user