jcc / laravel-vote

:tada: The package helps you to add user based vote system to your model.
MIT License
137 stars 15 forks source link

Is it possible to countVoter with eager loading ? #7

Open jay7793 opened 6 years ago

jay7793 commented 6 years ago

image

Is it possible to use this? image

Thank you.

nexxai commented 6 years ago

Seriously - can someone please add some form of local caching to this package? It's crazy that something as simple as this:

<div id="voteTotal-{{$feature->id}}" data-score-{{$feature->id}}="{{$feature->countTotalVotes()}}">
    {{$feature->countTotalVotes()}}
</div>

means two separate database calls because of the two calls to ->countTotalVotes()

LunarDevelopment commented 5 years ago

It doesn't solve your problem fully (caching is more useful) but you could make the best of it by assigning the results to a variable to reuse (psudo code.. Can't remember if @php() is right).

@php($countTotalVotes = $feature->countTotalVotes() )
<div id="voteTotal-{{$feature->id}}" data-score-{{$feature->id}}="{{$countTotalVotes}}">
    {{$countTotalVotes}}
</div>