I was create like button with current value on database and when the button has been clicked the value must be automatically updated on the view. Currently, the value was successfully updated on database, but not automatically updated on view.
Here is my jquery code:
<script type="text/javascript">
$(document).ready(function(){
$('#like').on('click', function(e){
var id = '{{$news->id}}';
$.get('{{ url('view/like')}}/'+id, function(data){
console.log(id);
console.log(data);
$('#like_data').empty();
$.each(data, function(index, element){
$('#like_data').append("<p>"+this.like+"</p>");
});
});
});
});
</script>
Here is my controller:
public function like($id){
$news = News::find($id);
$news->like += 1;
$news->save();
return $news;
}