diff --git a/app/Filament/Resources/RequestCharacteristicResource.php b/app/Filament/Resources/RequestCharacteristicResource.php index 63146d4..e8c5f63 100644 --- a/app/Filament/Resources/RequestCharacteristicResource.php +++ b/app/Filament/Resources/RequestCharacteristicResource.php @@ -437,17 +437,27 @@ class RequestCharacteristicResource extends Resource }) ->required() ->disabled(fn (Get $get) => ! empty($get('id'))), - Forms\Components\TextInput::make('model_type') + Forms\Components\Select::make('model_type') ->label('Model Type') ->reactive() ->nullable() + ->searchable() + ->required() + ->options(function () { + return [ + 'MOTOR' => 'MOTOR', + 'PUMP' => 'PUMP', + 'NAME_PLATE' => 'NAME_PLATE', + 'UNKNOWN' => 'UNKNOWN', + ]; + }) ->afterStateUpdated(function ($state, callable $set, callable $get) { $set('characteristic_name', null); $set('current_value', null); $set('update_value', null); $set('updated_by', Filament::auth()->user()?->name); }) - ->required() + ->default('MOTOR') ->disabled(fn (Get $get) => ! empty($get('id'))), Section::make('Request Characteristic Details') // ->columnSpan(['default' => 2, 'sm' => 4]) @@ -1308,9 +1318,23 @@ class RequestCharacteristicResource extends Resource TextInput::make('master_characteristic_field') ->label('Master Characteristic Field') ->placeholder('Enter Master Characteristic Field'), - TextInput::make('model_type') - ->label('Model Type') - ->placeholder('Enter Model Type'), + Select::make('model_type') + ->label('Search by Model Type') + ->nullable() + ->searchable() + ->reactive() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + $plantId = $get('Plant'); + + if ($userHas && strlen($userHas) > 0) { + return RequestCharacteristic::where('plant_id', $userHas)->pluck('model_type', 'model_type')->toArray(); + } elseif ($plantId) { + return RequestCharacteristic::where('plant_id', $plantId)->select('model_type')->distinct()->pluck('model_type', 'model_type'); + } else { + return RequestCharacteristic::select('model_type')->distinct()->pluck('model_type', 'model_type'); + } + }), Select::make('approver_status') ->label('Approver Status') ->options([ @@ -1397,7 +1421,7 @@ class RequestCharacteristicResource extends Resource } if (! empty($data['model_type'])) { - $query->where('model_type', 'like', '%'.$data['model_type'].'%'); + $query->where('model_type', $data['model_type']); } if (! empty($data['work_flow_id'])) {