Hello i'm developing like disliked system based on https://www.itsolutionstuff.com/post/php-laravel-5-like-dislike-system-tutorialexample.html
but the ajax function throwing internal server error
this is my controller
public function ajaxRequest(Request $request)
{
$post = Post::find($request->id);
$response = auth()->user()->toggleLiked($post);
return response()->json(['success' => $response]);
}
and this is my ajax request:
<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('i.glyphicon-thumbs-up, i.glyphicon-thumbs-down').click(function(){
var id = $(this).parents(".panel").data('id');
var c = $('#'+this.id+'-bs3').html();
var cObjId = this.id;
var cObj = $(this);
$.ajax({
type:'POST',
url:'/ajaxRequest',
data:{id:id},
success:function(data){
if(jQuery.isEmptyObject(data.success.attached)){
$('#'+cObjId+'-bs3').html(parseInt(c)-1);
$(cObj).removeClass("like-post");
}else{
$('#'+cObjId+'-bs3').html(parseInt(c)+1);
$(cObj).addClass("like-post");
}
}
});
});
$(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
});
});
</script>
this is the form for clicking the likes
<span class="pull-right">
<span class="like-btn">
<i id="like" class="glyphicon glyphicon-thumbs-up "></i>
<div id="like-bs3"></div>
<span>
</span>
what i have done is changing the routes in case it's missing something, but still throwing the same error, what should i do?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire