You can use map.
$orderDtls = DB::table('ordersmht')
->select(
'ordersmht.order_unq_id', // I want this to be trim or a variable on this place instead.
'ordersmht.item_no_input',
'ordersmht.supplier_barcode_input',
'ordersmht.item_name_input',
'ordersmht.item_unit_measure_input',
'ordersmht.item_quantity',
'ordersmht.item_cost_input',)
->where('ordersmht.order_unq_id', $val)
->paginate(500)
->map(fn($row) => [
'your_new_variable' => 'your value for it',
'item_no_input' => $row->item_no_input,
'supplier_barcode_input' => $row->supplier_barcode_input,
'item_name_input' => $row->item_name_input,
'item_unit_measure_input' => $row->item_unit_measure_input,
'item_quantity' => $row->item_quantity,
'item_cost_input' => $row->item_cost_input,
]);
if you need more logic, just loop over all data and change it then store it in a new array.