laravel - 如何在 laravel 集合中计数?
问题描述
这是我得到的收藏:
1 => App\Match_fact {#1332 ▼
#guarded: array:2 [▶]
#connection: "mysql"
#table: "match_facts"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:1 [▼
"goals" => 3
]
#original: array:1 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▶]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
]
}
我尝试了一个选项-> count($playerFacts->goals));
但它对我不起作用。我收到错误:
此集合实例上不存在属性 [目标]。
如何计算从集合中获得的所有值?
解决方案
然后 $playerFacts 是集合。
count($playerFacts);
推荐阅读
- reactjs - 已连接路由器 - 新路由的页面包含附加数据
- jmeter - jrpc通过jmeter调用
- time-series - 如何在 InfluxDB 订阅端点获取数据?
- android - 仍然不显示可展开的内容
- python - 从 FLOW 项目运行教程06“OpenStreetMap 中的网络”时出现文件错误
- node.js - 将 pm2 日志从 ec2 实例发送到 cloudwatch
- c# - 从后面的代码中获取变量值并在 aspx 页面中使用
- hosting - 当 NextJS 托管在 Vercel 上时,后端托管在哪里?
- node.js - 如何将一些 JS 库包含到 React 应用程序中
- sql - SQL Server 数据库关系图连接错误