本想把这个系列的laravel部分先走通再去填Vuejs的坑,学到这里,感觉不先把Vuejs怼下来是不行了~ ┑( ̄Д  ̄)┍
但是删掉之后点赞数就不会变了。怎么把点赞数的处理从这个函数里面分离出来呢?
那要怎么写才能解决问题呢,能给个思路吗?
如果不用异步,用普通的刷新页面的方式来处理,像这样:
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;
}
流程是走通了,但是刷新页面点赞数就增加的问题,要怎么解决呢?
嗯,刚才自己解决了。
@if (Auth::check())
<a href="/question/{$question->id}/follow"
class="btn btn-default {Auth::user()->followed($question->id) ? 'btn-success' : ''}">
{Auth::user()->followed($question->id) ? '已关注' : '关注该问题'}</a>
@else
<a href="/login" class="btn btn-default">关注问题</a>
@endif
这么简单的问题,不该问老师。
用户登陆的时候,功能都是正常的。但退出登陆之后,访问问题页面就会报错,这个问题要怎么解决呢:
ErrorException in da970cb938287b918147b2d72063f5c4456aeb18.php line 44:
Call to a member function followed() on null (View: D:\laragon\www\l53-zhihu\resources\views\question\show.blade.php)
<a href="/question/{$question->id}/follow"
class="btn btn-default {Auth::user()->followed($question->id) ? 'btn-success' : ''}">
{Auth::user()->followed($question->id) ? '已关注' : '关注该问题'}</a>
谢谢,看懂了。。。新手有时候会在一些不可思议的地方转不过弯来。
前面有几个系列的语速有点快,跟不上节奏。知乎这个系列的语速很合适,每小节后面的总结也很好。
这节里面QuestionController的owns方法不太理解,老师能解释一下吗?
public function owns(Model $model)
{
return $this->id == $model->user_id;
}