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:
dhanabalan
2025-09-29 16:35:55 +05:30
parent a4afe2f3c7
commit a9803f927f
34 changed files with 208 additions and 32 deletions

View File

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