<?php
namespace App\Nova\Metrics;
use App\Kunde;
use Illuminate\Http\Request;
use Laravel\Nova\Metrics\Value;
class TotalKunden extends Value
{
/**
* Calculate the value of the metric.
*
*@param \Illuminate\Http\Request $request
*@return mixed
*/
public function calculate(Request $request)
{
return $this->count($request, Kunde::class);
}
/**
* Get the ranges available for the metric.
**/
public function ranges()
{
return [
30 => '30 Tage',
60 => '60 Tage',
365 => '1 Jahr',
'MTD' => 'Seit Monatsbeginn',
'QTD' => 'Seit Quartalbeginn',
'YTD' => 'Seit Jahresanfang',
];
}
}
Do you have an associated eloquent model for the Nova resource? If not, you won't get the data. In other words, you create a Nova resource and associate it with a model such as App\Post with App\Nova\Post.
maybe someone has the same problem.. so the answer is:
metrics query is looking for the created_at column in the DB, so it must have an date
the metrics query is like this..
SELECT count(`id`) as aggregate FROM `Objects` WHERE `created_at` between '2018-11-05 12:51:22' and '2018-12-05 12:51:22' and `Objects`.`deleted_at` IS NULL
As @Torpedo mentioned above. You need dates on your model for the date range-based counts to work.
If you just want a simple count of records in the table for your model, then don't use the count method in your calculate method, use the result method instead.
Example:
/**
* Calculate the value of the metric.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function calculate(Request $request)
{
return $this->result(Kunde::count());
}
Note: Ranges won't work for this. So, you can disable them by returning [] in your ranges method.