From 795e930ec6d78c14ec1001f94e85b3dff9b45c4a Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 23 Dec 2025 11:21:04 +0530 Subject: [PATCH] Added plant and item characteritivcs id in resource page --- .../StickerStructureDetailResource.php | 60 ++++++++++++------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/app/Filament/Resources/StickerStructureDetailResource.php b/app/Filament/Resources/StickerStructureDetailResource.php index 3f254b0..a6c8981 100644 --- a/app/Filament/Resources/StickerStructureDetailResource.php +++ b/app/Filament/Resources/StickerStructureDetailResource.php @@ -6,6 +6,7 @@ use App\Filament\Exports\StickerStructureDetailExporter; use App\Filament\Imports\StickerStructureDetailImporter; use App\Filament\Resources\StickerStructureDetailResource\Pages; use App\Filament\Resources\StickerStructureDetailResource\RelationManagers; +use App\Models\ItemCharacteristic; use App\Models\StickerStructureDetail; use Filament\Facades\Filament; use Filament\Forms; @@ -34,6 +35,31 @@ class StickerStructureDetailResource extends Resource { return $form ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->relationship('plant', 'name') + ->reactive(), + Forms\Components\Select::make('item_characteristic_id') + ->label('Item') + ->reactive() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + + if (! $plantId) { + return []; + } + + return ItemCharacteristic::query() + ->whereHas('item', function ($query) use ($plantId) { + $query->where('plant_id', $plantId); + }) + ->with('item') + ->get() + ->mapWithKeys(fn ($ic) => [ + $ic->id => $ic->item->code, + ]); + }) + ->searchable(), Forms\Components\TextInput::make('sticker_id') ->label('Sticker ID') ->reactive() @@ -70,37 +96,27 @@ class StickerStructureDetailResource extends Resource ->default(fn ($get) => $get('sticker_id')) ->reactive() ->afterStateUpdated(function ($state, callable $set) { - \Log::info('Sticker ID Live:', ['sticker_id_live' => $state]); $set('sticker_id_live', $state); }), Forms\Components\ViewField::make('generate_template') ->view('fields.generate-template') ->reactive() - ->key(fn ($get) => 'generate-template' . ($get('sticker_id_live') ?? 'empty')) + //->key(fn ($get) => 'generate-template' . ($get('sticker_id_live') ?? 'empty')) + ->key(fn (Get $get) => + 'generate-template-' . + ($get('sticker_id_live') ?? 'empty') . '-' . + ($get('plant_id') ?? 'empty') . '-' . + ($get('item_characteristic_id') ?? 'empty') + ) + // ->viewData(fn (Get $get) => [ + // 'sticker_id' => $get('sticker_id_live') ?? 'empty', + // ]), ->viewData(fn (Get $get) => [ 'sticker_id' => $get('sticker_id_live') ?? 'empty', + 'plant_id' => $get('plant_id') ?? 'empty', + 'item_characteristic_id' => $get('item_characteristic_id') ?? 'empty', ]) - // ->extraAttributes([ - // // Pass the current sticker_id typed by the user - // //'sticker_id' => fn ($get) => $get('sticker_id'), - // 'sticker_id' => fn ($get) => $get('sticker_id') ?? 'empty', - - - // // 'sticker_id' => function ($get) { - // // \Log::info('ViewField closure executed'); - - // // $stickerId = $get('sticker_id'); - - // // // Use Laravel log to see value in real time - // // \Log::info('Sticker ID in ViewField:', $stickerId); - - // // // You can also temporarily dd(), but it will stop form render - // // // dd($stickerId); - - // // return $stickerId; - // // }, - // ]), ]); } -- 2.49.1