title: laravel delete sweetalert 1 javascript
body: <p>my confirmation sweetalert didn't work for delete. but it already show the pop up function for sweetalert. yes button cant read my controller for delete the data. </p>
  
  <p>form</p>
  
  <pre><code>&lt;form action="{{url('/Admin/Page/Carousel/delete')}}" method="post"&gt;
      &lt;input type="hidden" name="_token" value="{{csrf_token()}}"&gt;
      &lt;input type="hidden" name="id" value="{{$datas-&gt;id}}"&gt;
      &lt;button type="submit" class="btn btn-danger delete"&gt;&lt;i class="fas fa-trash"&gt;&lt;/i&gt;&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>js</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function(){
          $('.delete').click(
          function(e){
              var button = $(this);
              e.preventDefault();
              swal({
                  title: "Are you sure ?",
                  text: "Data",
                  type: "warning",
                  confirmButtonClass: "btn-danger",
                  confirmButtonText: "Yes!",
                  showCancelButton: true,
                  confirmButtonColor: '#DD6B55',
                  confirmButtonText: 'Delete!'
              }).then((result) =&gt; {
                  if(result.value){
                      button.closest('form').submit();
                  }
              })
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Route</p>
  
  <pre><code>Route::post('/Admin/Page/Carousel/delete','adminController@postdeleteCarousel');
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>function postdeleteCarousel(Request $req){
      $id = $req-&gt;input('id');
  
      Carousel::find($id)-&gt;delete();
  
      $req-&gt;session()-&gt;flash("pesan", "Delete Carousuel Success!");
      $req-&gt;session()-&gt;flash("title", "Delete Success!");
      $req-&gt;session()-&gt;flash("alert", "success");
      return redirect('/Admin/Page/carousel');
  }
  </code></pre>