Added plant and item characteritivcs id in resource page #49
@@ -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;
|
||||
// // },
|
||||
// ]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user