Added plant and item characteritivcs id in resource page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Failing after 8s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 22s
Laravel Pint / pint (pull_request) Failing after 3m3s
Laravel Larastan / larastan (pull_request) Failing after 3m25s

This commit is contained in:
dhanabalan
2025-12-23 11:21:04 +05:30
parent 6d2ae5a324
commit 795e930ec6

View File

@@ -6,6 +6,7 @@ use App\Filament\Exports\StickerStructureDetailExporter;
use App\Filament\Imports\StickerStructureDetailImporter; use App\Filament\Imports\StickerStructureDetailImporter;
use App\Filament\Resources\StickerStructureDetailResource\Pages; use App\Filament\Resources\StickerStructureDetailResource\Pages;
use App\Filament\Resources\StickerStructureDetailResource\RelationManagers; use App\Filament\Resources\StickerStructureDetailResource\RelationManagers;
use App\Models\ItemCharacteristic;
use App\Models\StickerStructureDetail; use App\Models\StickerStructureDetail;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
@@ -34,6 +35,31 @@ class StickerStructureDetailResource extends Resource
{ {
return $form return $form
->schema([ ->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') Forms\Components\TextInput::make('sticker_id')
->label('Sticker ID') ->label('Sticker ID')
->reactive() ->reactive()
@@ -70,37 +96,27 @@ class StickerStructureDetailResource extends Resource
->default(fn ($get) => $get('sticker_id')) ->default(fn ($get) => $get('sticker_id'))
->reactive() ->reactive()
->afterStateUpdated(function ($state, callable $set) { ->afterStateUpdated(function ($state, callable $set) {
\Log::info('Sticker ID Live:', ['sticker_id_live' => $state]);
$set('sticker_id_live', $state); $set('sticker_id_live', $state);
}), }),
Forms\Components\ViewField::make('generate_template') Forms\Components\ViewField::make('generate_template')
->view('fields.generate-template') ->view('fields.generate-template')
->reactive() ->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) => [ ->viewData(fn (Get $get) => [
'sticker_id' => $get('sticker_id_live') ?? 'empty', '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;
// // },
// ]),
]); ]);
} }