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 >
<span >
<i id="like{{$post->id}}" ></i>
<div id="like{{$post->id}}-bs3">{{ $post->likers()->get()->count() }}</div>
<span>
</span>
this is the error "local.ERROR: Method Illuminate\Database\Query\Builder::toggleLiked does not exist. "
i use overtrue/laravel-follow package for like and dislike system
what i have done is changing the routes in case it's missing something, but still throwing the same error, what should i do?
ANSWER:
turns out it happens in the controller. its supposed to be toggleLike. meanwhile i type toggleLiked
thank you in advanced
CodePudding user response:
It's better if you post it with error log.
You can use below commands and try again.
- php artisan cache:clear
- php artisan config:clear
- php artisan config:cache
CodePudding user response:
Check Laravel version with your project and overtrue/laravel-follow package