title: How do I stop Create action from execution in laravel while there is some dependency error
body: <p>I am creating user from the details I get from the user details table, </p>
  
  <p><strong><em>My Controller</em></strong></p>
  
  <pre><code> public function store(Request $request)
      {
  
  // Section 1
  
   $user = User::create(
              [
                  'name' =&gt; $request-&gt;input('first_name'),
                  'email' =&gt; $request-&gt;input('email'),
                  'row_status' =&gt; '1',
                  'user_type' =&gt; '3',
                  'password' =&gt; bcrypt('RandomPassword@123')
  
              ]
          );
  
  // Section 2
  
          $technician_register = new Technician();
          $technician_register-&gt;user_id = $user-&gt;id;
          $technician_register-&gt;first_name = $request-&gt;input('first_name');
           if ($request-&gt;hasFile('avatar_image')) {
              $avatar_image = $request-&gt;file('avatar_image');
              $extension = $avatar_image-&gt;getClientOriginalExtension();
              $filename =  $request-&gt;input('first_name') . date('Y-M-d') .  '.' . Str::random(3) . "." . $extension;
              $location = public_path('assets/images/technician_avatar/' . $filename);
              Imag::make($avatar_image)-&gt;resize(300, 300)-&gt;save($location);  // the Image is spelled wrong purposefully to replicate an error.
              $technician_register-&gt;avatar_image = $filename;
          }  
          $technician_register-&gt;save();
  
     if ($technician_register) {
          Session::flash('success', 'Selected record has been successfully saved');
          return back();
      } else {
          $user_delete = User::findOrFail($user-&gt;id);
          $user_delete-&gt;delete();
          Session::flash('error', 'Error');
          return back();
  
      //This block doesn't seem to work!!
      }
  
      }
  </code></pre>
  
  <p>I am getting error in the secound section where as the section 1 being executed. How do I stop or reverse the action from happening if there is any error</p>