如果不用异步,用普通的刷新页面的方式来处理,像这样:
view:
<a href="/answer/{$answer->id}/votes" class="pull-right btn btn-default
{Auth::user()->isVoted($answer->id) ? "btn-primary" : ""}">
{$answer->votes_count}
</a>
public function isVoted($answer_id)
{
$count = $this->votes()->where('answer_id', $answer_id)->count();
if ($count > 0){
$this->votes()->find($answer_id)->increment('votes_count');
return true;
}
return false;
}
流程是走通了,但是刷新页面点赞数就增加的问题,要怎么解决呢?