title: Ajax request for delete image doesnt work in laravel
body: <p>I want to delete the image in the preview box, as well as delete it in the database using ajax. Deleting the image in the preview box was successful, but deleting it from the database didn't work.
  <a href="https://postimg.cc/Lh65p5nt" rel="nofollow noreferrer"><img src="https://postimg.cc/Lh65p5nt" alt="screenshoot" /></a></p>
  <p>here my ajax:</p>
  <pre><code>$(document).ready(function() {
          document.getElementById('pro-image').addEventListener('change', readImage, false);
          $(&quot;.preview-images-zone&quot;).sortable();
          $(document).on('click', '.image-cancel', function() {
              let no = $(this).data('no');
              let idData = $(this).data('id');
              $(&quot;.preview-image.preview-show-&quot; + no).remove();
              $.ajax({
                  type: 'POST',
                  url: '{{url(&quot;unit/API/simpan&quot;)}}',
                  data: {
                      'id': idData
                  },
                  success: function(data) {
                      alert('success');
                  }
              });
          });
  
      });
  </code></pre>
  <p>My Html:</p>
  <pre><code>&lt;!-- Percobaan Preview --&gt;
                          &lt;fieldset class=&quot;form-group&quot;&gt;
                              &lt;div class=&quot;offset-md-2 col-md-6&quot;&gt;
                                  &lt;a href=&quot;javascript:void(0)&quot; onclick=&quot;$('#pro-image').click()&quot; class=&quot;btn btn-primary&quot;&gt;Upload Gambar&lt;/a&gt;
                                  &lt;input type=&quot;file&quot; id=&quot;pro-image&quot; name=&quot;gambarku[]&quot; style=&quot;display: none;&quot; class=&quot;form-control&quot; multiple&gt;
  
                              &lt;/div&gt;
                          &lt;/fieldset&gt;
                          &lt;div class=&quot;preview-images-zone offset-md-2 col-md-8&quot;&gt;
                              &lt;!-- Gambar Utama  --&gt;
                              &lt;div class=&quot;preview-image preview-show-1&quot;&gt;
                                  &lt;div class=&quot;image-cancel&quot; data-no=&quot;1&quot;&gt;x&lt;/div&gt;
                                  &lt;div class=&quot;image-zone&quot;&gt;&lt;img id=&quot;pro-img-1&quot; src=&quot;{{asset('storage/rumah/'.$rumahku-&gt;gambar_rumah)}}&quot;&gt;&lt;/div&gt;
  
                              &lt;/div&gt;
                              &lt;!-- Gambar Tambahan --&gt;
                              &lt;?php $counter = 2 ?&gt;
                              @foreach($rumahku-&gt;gambar as $rows)
                              &lt;div class=&quot;preview-image preview-show-{{$counter}}&quot;&gt;
                                  &lt;div class=&quot;image-cancel&quot; data-no=&quot;{{$counter}}&quot; data-id=&quot;{{$rows-&gt;id_gambar}}&quot;&gt;x&lt;/div&gt;
                                  &lt;div class=&quot;image-zone&quot;&gt;&lt;img id=&quot;pro-img-{{$counter}}&quot; src=&quot;{{asset('storage/rumah/'.$rows-&gt;gambar_unit)}}&quot;&gt;&lt;/div&gt;
                              &lt;/div&gt;
                              &lt;?php $counter++ ?&gt;
                              @endforeach
                          &lt;/div&gt;
  
                          &lt;!-- /preview --&gt;
  </code></pre>
  <p>my route</p>
  <pre><code>Route::post('unit/API/simpan/{id}', 'partner\UnitController@simpanGambar');
  </code></pre>
  <p>my controller</p>
  <pre><code>public function simpanGambar($id)
  {
      $gambar = Gambar::find($id);
      $gambar-&gt;delete();
  }
  </code></pre>