How to prevent repeating the same option value of a selection in a php loop
public function getProductById(Request $request)
{
$response = '';
$product = Product::find($request->productId);
$groups = Group::all();
foreach ($groups as $group) {
if ($group->id != $product->group_id) {
//exclude this record
$response .= "<option value='" . $group->id . "'>";
$response .= $group->group_name;
$response .= "</option>";
}
}
}