From 7cd0db415ca8debef853edd0f06f0df9a8d1ba57 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 1 Apr 2025 16:19:32 +0530 Subject: [PATCH] Loading foreign key value while update for productionQuantity --- .../Resources/ProductionQuantityResource.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/Filament/Resources/ProductionQuantityResource.php b/app/Filament/Resources/ProductionQuantityResource.php index 91f52af..2972956 100644 --- a/app/Filament/Resources/ProductionQuantityResource.php +++ b/app/Filament/Resources/ProductionQuantityResource.php @@ -8,6 +8,7 @@ use App\Filament\Resources\ProductionQuantityResource\RelationManagers; use App\Models\ProductionQuantity; use Filament\Forms; use Filament\Forms\Form; +use Filament\Forms\Get; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Actions\ImportAction; @@ -37,6 +38,7 @@ class ProductionQuantityResource extends Resource ->required() // ->nullable() ->reactive() + ->disabled(fn (Get $get) => !empty($get('id'))) // ->afterStateUpdated(fn ($set) => $set('block_name', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { $plantId = $get('plant_id'); @@ -71,8 +73,20 @@ class ProductionQuantityResource extends Resource ->reactive() // ->afterStateUpdated(fn ($set) => $set('shift_id', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionQuantity::where('id', $get('id'))->first(); + $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first(); + if($getBlock->block_id) + { + $set('block_name', $getBlock->block_id); + $set('pqBlockError', null); + } + } + $blockId = $get('block_name'); $set('shift_id', null); + if (!$blockId) { $set('pqBlockError', 'Please select a block first.'); return; @@ -105,8 +119,19 @@ class ProductionQuantityResource extends Resource ->reactive() ->afterStateUpdated(fn ($set) => $set('line_id', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionQuantity::where('id', $get('id'))->first(); + if($getShift->shift_id) + { + $set('shift_id', $getShift->shift_id); + $set('pqShiftError', null); + } + } + $shiftId = $get('shift_id'); $set('line_id', null); + if (!$shiftId) { $set('pqShiftError', 'Please select a shift first.'); return; @@ -142,7 +167,18 @@ class ProductionQuantityResource extends Resource }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionQuantity::where('id', $get('id'))->first(); + if($getShift->line_id) + { + $set('line_id', $getShift->line_id); + $set('pqLineError', null); + } + } + $lineId = $get('line_id'); + $set('item_code', null); if (!$lineId) { $set('pqLineError', 'Please select a line first.'); @@ -397,6 +433,9 @@ class ProductionQuantityResource extends Resource ->readOnly(true) ->autocapitalize('serial_number'), //->columnSpanFull(), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), ]) ->columns(2), ]);