diff --git a/app/Filament/Resources/TestingPanelReadingResource.php b/app/Filament/Resources/TestingPanelReadingResource.php index 93d2ebad1..a16496201 100644 --- a/app/Filament/Resources/TestingPanelReadingResource.php +++ b/app/Filament/Resources/TestingPanelReadingResource.php @@ -119,22 +119,34 @@ class TestingPanelReadingResource extends Resource ->reactive(), Forms\Components\Select::make('motor_testing_master_id') ->label('Item Code') - ->relationship('motorTestingMaster', 'item.code') + //->relationship('motorTestingMaster', 'item.code') + // ->options(function (callable $get) { + // $plantId = $get('plant_id'); + // if (!$plantId) { + // return []; + // } + // return MotorTestingMaster::with('item') + // ->where('plant_id', $plantId) + // ->get() + // //->filter(fn ($mtm) => $mtm->item) + // ->pluck('item.code', 'id') + // ->toArray(); + // }) ->options(function (callable $get) { $plantId = $get('plant_id'); if (!$plantId) { return []; } - - // return MotorTestingMaster::with('item') - // ->whereHas('motorTestingMasters', function ($query) use ($plantId) { - // $query->where('plant_id', $plantId); - // })->pluck('item.code', 'id')->toArray(); - // // ->get(); - - return Item::where('plant_id', $plantId)->whereHas('motorTestingMasters')->pluck('code', 'id')->toArray(); - // return Item::whereHas('motorTestingMasters')->pluck('code', 'id')->toArray(); + return MotorTestingMaster::query() + ->join('items', 'motor_testing_masters.item_id', '=', 'items.id') + ->where('motor_testing_masters.plant_id', $plantId) + ->select('motor_testing_masters.id', 'items.code') + ->pluck('items.code', 'motor_testing_masters.id') + ->toArray(); }) + // ->getOptionLabelUsing(fn ($value) => + // MotorTestingMaster::with('item')->find($value)?->item?->code + // ) ->required() ->searchable() ->reactive(),