title: how to use SQL Transaction in laravel 5.4?
body: <p>how to use Sql Transaction in this code sample. i tried but transaction is not working properly. my database engine is InnoDB. </p>
  
  <pre><code> DB::transaction(function() use($request  ) {
   $user = User::$request-&gt;only('name','mobile','address');
   $userSave = User::create($user)-&gt;id;
  
   foreach ( $request-&gt;subjects as $items)
   {
  
    $data = User::$request-&gt;only('name');
     $data['student_id'] = $userSave
      $subject= Subject::create($data);
  
     }
    } //sql transaction end
  </code></pre>
  
  <p>I  can not explain this better way .. so please read code and correct it. if i am wrong. problem is, it is  not rollback if subject model query gone failed. </p>