Support the ongoing development of Laravel.io →
Input Database Forms
Last updated 2 years ago.
0
Solution

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

Last updated 2 years ago.
0

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>
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.