dimanche 21 juin 2020

Laravel sweetalert deleting id

how does the error comes up in route is there something went wrong to my code? my route is correct inside script in url, how can i fix?

This is my route web.php

Route::post('deletenews/{id}', 'AllSystemController@deletenewsdata')->name('delete.news.data');

this is my loop inside my blade

 @foreach($news as $row)
 <tr>
<td><img src="/" class="img-thumbnail" width="50"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="dropdown">
  <button class="btn btn-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">&nbsp;<i class="feather icon-chevron-down"></i></button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
    <a style="color:black; font-weight: bold;" class="dropdown-item" href="" target="_blank">View</a>
    <a style="color:black; font-weight: bold;" class="dropdown-item" href="" target="_blank" class="btn btn-primary">Edit</a>
    <a onclick="deleteConfirmation()" style="color:black; font-weight: bold;" class="dropdown-item">Delete</a>
  </div>
  </div>
 </td>

 </tr>
 @endforeach

this is my script inside my blade

<script type="text/javascript">
function deleteConfirmation(id) {
    swal({
        title:"Are you sure you want to delete this?",
        text: "You won't be able to revert this!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#d33',
        cancelButtonColor: '#3085d6',
        cancelButtonText: "No, cancel!",
        confirmButtonText: "Yes, delete it!",
    }).then(function (e) {

        if (e.value === true) {
            var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
            $.ajax({
                type: 'POST',
                url: "/" + id,
                data: {_token: CSRF_TOKEN},
                dataType: 'JSON',
                success: function (results) {
                    if (results.success === true) {
                        swal({
                          title: "Done!",
                          text: results.message,
                          type: "success",
                          showConfirmButton: false
                        });
                        location.reload(true);
                        
                    } else {
                        swal({
                          title: "Error!",
                          text: results.message,
                          type: "error"
                        });
                        location.reload(true);
                        // swal("Error!", results.message, "error");
                    }
                }
            });

        } else {
            e.dismiss;
        }

    }, function (dismiss) {
        return false;
    })
}
</script>

Error: POST http://localhost/kauswagan/deletenews/8 500 (Internal Server Error)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire