استفاده از transaction در حلقه foreach در لاراول

به شکل زیر عمل کنید:

$dbConn->begin_transaction();

try{

    foreach($ítems as $item){
        //Whatever you are going to do
    }

    if($dbConn->commit()){

    //Notify buyer about all the transactions, the user doesn't receives the notification unless the commit was succesful

   }

catch(Exception ex){
    $dbConn->rollback();
}

منبع: کلیک کنید