title: How to update image using controller in laravel?
body: <p>I want to update user image but it's not getting updated. I have used following controller for updating the image.. Can you suggest what's the mistake in controller function? </p>
  
  <p>View part :</p>
  
  <pre><code>&lt;div class="form-group"&gt;
              &lt;label&gt;Image Upload&lt;/label&gt;
              &lt;input type="file" name="image"  id="image"&gt;&lt;img src="{{ asset('public/images/' . $course-&gt;image) }}" width="200px"/&gt;&lt;/br&gt;
   &lt;/div&gt; 
  </code></pre>
  
  <p>Controller function :</p>
  
  <pre><code>public function update(Request $request, $id)
  {
      $data=Course::findOrFail($id);  
  
  
      if ($request-&gt;hasFile('image'))
          {
              $file = $request-&gt;file('image');
              $timestamp = str_replace([' ', ':'], '-', Carbon::now()-&gt;toDateTimeString()); 
              $name = $timestamp. '-' .$file-&gt;getClientOriginalName();
              $data-&gt;image = $name;
              $file-&gt;move(public_path().'/images/', $name);                       
          }   
               $data-&gt;course_code = $request['course_code'];
               $data-&gt;course_title = $request['course_title'];
               $data-&gt;course_credit = $request['course_credit'];
  
            $data-&gt;save();             
        return redirect('course');
  }
  </code></pre>