繁体   English   中英

在整数 Laravel 5.4 上调用成员函数 count()

[英]Call to a member function count() on integer Laravel 5.4

我有名为 cat_id 的数据库行,在这一行我有 1-17 的类别 ID

http://prntscr.com/mgrlbz

我如何显示第 17 类的数量?

将此添加到您的控制器

$data['count'] = your_table::where('cat_id',17)->count();
return view("YOUR_VIEW_PATH", $data);

在您的刀片模板中使用它

<div>{!! $count !!}</div>

使用sql查询

SELECT COUNT(*) from table_name where cat_id = 17

或者,如果您有像$rows = data_array这样的查询结果,那么您可以像这样使用 php

$count = count(array_filter($rows, function($item) { return $item['cat_id'] === 17; }));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM