diff --git a/app/Filament/Resources/ProductionLineStopResource.php b/app/Filament/Resources/ProductionLineStopResource.php index 0301077..42d1062 100644 --- a/app/Filament/Resources/ProductionLineStopResource.php +++ b/app/Filament/Resources/ProductionLineStopResource.php @@ -8,6 +8,7 @@ use App\Filament\Resources\ProductionLineStopResource\RelationManagers; use App\Models\ProductionLineStop; use Filament\Forms; use Filament\Forms\Form; +use Filament\Forms\Get; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Actions\ImportAction; @@ -39,6 +40,7 @@ class ProductionLineStopResource 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,10 +73,31 @@ class ProductionLineStopResource extends Resource ->toArray(); }) ->reactive() + // ->default(function (callable $get, callable $set) { + // if ($get('id')) { + // $getShift = ProductionLineStop::where('id', $get('id'))->first(); + // $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first(); + // // dd($getBlock->block_id); + // $set('block_name', $getBlock->block_id); + // } + // // return null; // Return null if no default value should be set + // }) // ->afterStateUpdated(fn ($set) => $set('shift_id', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionLineStop::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('plsBlockError', null); + } + } + $blockId = $get('block_name'); $set('shift_id', null); + if (!$blockId) { $set('plsBlockError', 'Please select a block first.'); return; @@ -102,7 +125,6 @@ class ProductionLineStopResource extends Resource if (!$get('plant_id') || !$get('block_name')) { return []; } - // // Get the block ID based on plant_id and block_name // $block = \App\Models\Block::where('plant_id', $get('plant_id')) // ->where('name', $get('block_name')) @@ -123,8 +145,19 @@ class ProductionLineStopResource extends Resource ->reactive() // ->afterStateUpdated(fn ($set) => $set('line_id', null)) ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionLineStop::where('id', $get('id'))->first(); + if($getShift->shift_id) + { + $set('shift_id', $getShift->shift_id); + $set('plsShiftError', null); + } + } + $shiftId = $get('shift_id'); $set('line_id', null); + if (!$shiftId) { $set('plsShiftError', 'Please select a shift first.'); return; @@ -159,7 +192,18 @@ class ProductionLineStopResource extends Resource }) ->reactive() ->afterStateUpdated(function ($state, callable $set, callable $get) { + if($get('id')) + { + $getShift = ProductionLineStop::where('id', $get('id'))->first(); + if($getShift->line_id) + { + $set('line_id', $getShift->line_id); + $set('plsLineError', null); + } + } + $lineId = $get('line_id'); + if (!$lineId) { $set('plsLineError', 'Please select a line first.'); return; @@ -243,6 +287,9 @@ class ProductionLineStopResource extends Resource // ->dehydrated(false) ->readOnly(true) ->numeric(), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), ]) ->columns(2), ]);