Good I am trying to delete through ajax but I get the following error:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
I searched the error and apparently appears by the token so I have done what they recommended, I added in the view this:
<meta name="csrf-token" content="">
and ajax:
$('#delete').on('click', function(){
var x = $(this);
var delete_url = x.attr('data-href')+'/'+x.attr('data-id');
$.ajax({
url: delete_url,
type:'DELETE',
headers:{"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr('content')},
success:function(result){
alert('success');
},
error:function(result){
alert('error');
}
});
});
controller:
public function destroy($id)
{
$appointment = Appointment::find($id);
if(appointment == null){
return Response()->json([
'message'=>'error delete.'
]);
}
$appointment->delete();
return Response()->json([
'message'=>'sucess delete.'
]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire