title: Only update image if user uploaded a new one, Laravel
body: <p>I have an edit form which has an image field where a user can upload a new image if he wants to.</p>
  
  <p>But if the user does not upload a new photo I don't want to validate the image field and just use the photo that's already in the database. And not update the image field at all.</p>
  
  <p>Here is my edit function:</p>
  
  <pre><code>public function postEdit($id) {
  
      $product = Product::find($id);
  
      // This should be in product model, just testing here
      $edit_rules = array(
          'category_id' =&gt; 'required|integer',
          'title' =&gt; 'required|min:2',
          'description' =&gt; 'required|min:10',
          'price' =&gt; 'required|numeric',
          'stock' =&gt; 'integer'
      );
  
      // Add image rule only if user uploaded new image
      if (Input::has('image')) {
          $edit_rules['image'] = 'required|image|mimes:jpeg,jpg,bmp,png,gif';
      }
  
      $v = Validator::make(Input::all(), $edit_rules);
  
      if ($product) {
  
          if ($v-&gt;fails()) {
              return Redirect::back()-&gt;withErrors($v);
          }
  
          // Upload the new image
          if (Input::has('image')) {
              // Delete old image
              File::delete('public/'.$product-&gt;image);
  
              // Image edit
              $image = Input::file('image');
              $filename = date('Y-m-d-H:i:s')."-".$image-&gt;getClientOriginalName();
              Image::make($image-&gt;getRealPath())-&gt;resize(600, 600)-&gt;save('public/img/products/'.$filename);
  
              $product-&gt;image = 'img/products/'.$filename;
              $product-&gt;save();
          }
  
          // Except image because already called save if image was present, above
          $product-&gt;update(Input::except('image'));
  
          return Redirect::to('admin/products')-&gt;with('message', 'Product updated.');
      }
  
      return Redirect::to('admin/products');
  }
  </code></pre>
  
  <p>Using this I can update all the values except the image. </p>
  
  <p>If I don't upload a new photo it saves all other updated values.</p>
  
  <p>If I do upload a new photo it just ignores it and saves all other updated values, doesn't upload the new photo.</p>