You could wrap each upsert in a try catch with transactions. Then you can catch the failed chunk and roll it back if it fails https://laravel.com/docs/9.x/database#database-transactions
Sep 22, 2022
2
Level 1
upsert() failed records
Hello, I have a table with name with product_campaigns (example). This table has "campaign_id", "product_id" FK columns and "price" column.
I'm using job batches to upsert data to this table, sometimes i'm upserting 50k records with chunk. But i need to show a report for failed records to customers like "failed at product id 15 and 17...". Anyone know a way to detect failed rows while upserting?
Kind regards.
Please or to participate in this conversation.