[英]Call to a member function count() on integer Laravel 5.4
I have database row called cat_id and in this row i have categories id's from 1-17我有名为 cat_id 的数据库行,在这一行我有 1-17 的类别 ID
http://prntscr.com/mgrlbz http://prntscr.com/mgrlbz
How could i show count of category no 17?我如何显示第 17 类的数量?
Add this to your controller将此添加到您的控制器
$data['count'] = your_table::where('cat_id',17)->count();
return view("YOUR_VIEW_PATH", $data);
Use it in your blade template在您的刀片模板中使用它
<div>{!! $count !!}</div>
Using sql query使用sql查询
SELECT COUNT(*) from table_name where cat_id = 17
Or if you have query results like $rows = data_array
then you can use php like或者,如果您有像$rows = data_array
这样的查询结果,那么您可以像这样使用 php
$count = count(array_filter($rows, function($item) { return $item['cat_id'] === 17; }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.