我有这些模特: ForumCategory 论坛 话题 回复
在主论坛页面中,我想计算并显示与此论坛相关的回复数量。 所有模型都有关系。
这是观点:
%binomial coefficients
function nk=nchoosek2(n, k)
if n-k > k
nk = prod((k+1:n) .* prod((1:n-k).^ (-1/(n-k))));
else
nk = prod((n-k+1:n) .* prod((1:k).^ (-1/k)) ) ;
end
end
%function to store and retrieve results of nchoosek to/from a table
function ret = choose (n,k, D, K1, K2)
persistent binTable = zeros(max([D+1,K1+K2+1]) , D+1);
if binTable(n+1,k+1) == 0
binTable(n+1,k+1) = nchoosek2(n,k);
end
ret = binTable(n+1,k+1);
end
function P = tst()
P=0;k1=150; k2=150; D=200; P=0;
choose(1,0,D,k1,k2);
for i = 0:D-1
for j = j=max(i - k2 , 0):min (i,k1-1)
P=P+choose(k1,j)*choose(k2,i-j)/choose((k1+k2),i);
end
end
end
此行不起作用:
@foreach ($categories as $category)
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default striped">
<div class="panel-heading">
<div class="row">
<div class="col-md-11"><a href="#">{{ $category->name }}</a></div>
<div class="col-md-1 text-right"><a><span class="fa fa-arrow-down"></span></a></div>
</div>
</div>
@foreach ($category->forums as $forum)
<div class="panel-body">
<div class="row">
<div class="col-md-1 text-right"><span class="fa fa-envelope fa-4x"></span></div>
<div class="col-md-7">
<h4>
<a href="forum/{{ $forum->id }}/{{ urlencode($forum->name) }}">{{ $forum->name }} </a>
<br>
<small>{{ $forum->description }}</small>
</h4>
</div>
<div class="col-md-1 post-num">
<h5>{{ $forum->topics->count() }}<br>
<small>Topics</small></h5>
<h5>{{ $forum->topics->replies->count() }}<br>
<small>Replies</small></h5>
</div>
<div class="col-md-3">
<img src="" class="img-circle last-comnt-img">
<a href="#">Last comment</a><br>
By <a href="#">Username</a><br>
<span class="text-muted">12:31</span>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
@endforeach