簡體   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