我如何计算 Laravel 中仪表板上的特定列?

How do i count a specific column on the dashboard in Laravel?

下面是我如何在仪表板上查看我存储的所有设备的计数,其中 'devices' 是存储在我的数据库中的所有设备。我想查看一行中使用特定列名的计数。我该怎么做!有帮助吗?

@inject('devices', 'App\Device')

<div class="number"><strong>{{ $devices->count() }}</strong></div>

你在找这个吗?

$devices->where('column', 'matches')->count();

或者类似这样的东西……

$devices->select('yourColumn', DB::raw('count(*) as total'))->groupBy('yourColumn')->get()

所以我发现我必须做这样的事情:

{{ $devices->where('Type_ID', 'Laptop')->count() }}

来自:<div class="number"><strong>{{ $devices->count() }}</strong></div>

像这样的东西,它完美地工作:

<div class="number"><strong>{{ $devices->where('Type_ID', 'Laptop')->count() }}</strong></div>