title: Laravel transaction saves data into DB even when it's rollbacked
body: <p>I send a request, trying to save multiple documents at once.</p>
  
  <p>Here is my code</p>
  
  <pre><code>DB::beginTransaction();
  
  try {
      foreach ($request-&gt;documents as $index =&gt; $documentInfo) {
          // Check
          if (// some statement) {
  
              $documentExists = Document::where([
                  // some checks
              ])
              -&gt;exists();
  
              if ($documentExists) {
                  throw new \Exception("Error Processing Request", 1);
              }
          }
  
  
          // Assign document properties
  
          $document-&gt;save(); 
      }
  
      DB::commit();
  } catch (\Exception $e) {
      DB::rollBack();
  
      if ($request-&gt;ajax()) {
          return response()-&gt;json([
              'success' =&gt; false, 
              'document' =&gt; $index,
              'message' =&gt; '// message',
          ]);
      }
  
      return redirect()-&gt;back()-&gt;with('error', '// message');
  }
  </code></pre>
  
  <p>The thing that happens is that I check every document for its own unique values. If two documents with same values try to get saved I want to return an error.
  I tried uploading two documents with the same values, the error is returned on the second document and the transaction must fail, but the first document gets saved into the database. 
  I don't want this, if there is an error I don't want any documents saved into the DB.</p>