Hi Sergio!
My idea would be to return the vote-count with the AJAX request, thus saving the extra GET request:
You would have to add the follwing code to the route in PHP:
if(Request::ajax()){
...
// Return the publication vote count to the AJAX request
return Profilepublicationvote::where('publication_id', $publicationid)->where('vote', '1')->count();
}
You would then change the Javascript code as follows:
success: function (data) {
$('.success_message').hide().html('');
$(form)[0].reset();
console.log("Esta funcionando");
$('.success_message').show().html(data.message);
// Update the vote count field
$('.votes').text( data );
},
Hope this helps!
Regards
Hi sisou, it works :) But when I do the vote change count of all the publications.
My HTML:
<li class="like-publication">
<span>{{HTML::image(URL::to('img/widgets/likesocialmeet.png'),'Like')}}</span>
<span class="votes">
{{Publication::find($publication->id)->profilepublicationvotes->sum('vote')}}
</span>
{{ Form::open(array('url' => 'profilepublicationvotelike', 'class' => 'vote_ajax')) }}
<input type="text" id="disabledTextInput" style="display:none" name="vote" value='1'>
<input type="text" id="disabledTextInput" style="display:none" name="user_id" value="{{ Auth::user()->id }}">
<input type="text" id="disabledTextInput" style="display:none" name="publication_id" value="{{ $publication->id }}">
{{ Form::submit('vote', array('class' => 'button expand round')) }}
{{ Form::close() }}
</li>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community