I am adding the barcode with product SKU and product ID in a table using below code:-
File Path: /app/code/[NameSpace]/[ModuleName]/Model/ResourceModel/Custom.php
public function generateBarcodes($object, $attribute, $barcode, $_product)
{
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$barcodeModel = $objectManager->create('VendorModuleModelBarcode');
$data = array(
'barcode' => $barcode,
'product_id' => $_product->getId(),
'qty' => 1,
'product_sku' => $_product->getSku(),
'supplier_code' => '',
'history_id' => 0000
);
$barcodeModel->setData($data);
$barcodeModel->save();
}
but I want to stop duplicate record in table, Please let me know how to achieve this in above code.