我正在尝试执行此SQL语句,并使用刀片引擎将其输出:
" SELECT SUM(like) FROM likes WHERE post_id = ". $post->id. " AND source_id IS NOT '' "
我不知道该怎么做,昨天我尝试了一下,但是没有用:
{{$post->likes->where('post_id', $post->id)->where('source_id', '<>', '')->sum('like')}}
在喜欢表“属于关联”两个源表和职位表。
编辑:
我使用Laravel版45年2月5日
您可以使用whereNotNull()
方法。
https://laravel.com/docs/5.3/queries#where-clauses
更新
似乎$posts
是一个集合。在这种情况下,您必须使用filter()
。例如:
$collection->filter(function ($item) {
return $item['some_value'] !== null;
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句