为什么在新星度量中不起作用?

时间:2019-01-04 11:03:46

标签: php laravel laravel-nova

如果我计算User :: class模型,则指标有效, 但是当我将其更改为其他模型时,指标会显示

“ 0无数据”

<?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.
  *
 *
public function calculate()
{
return $this->result(Kunde::count());
}
 *
  *@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',

    ];
}

}   

资源中引用了我的模型

具有:

    public static $model = 'App\Kunde';

并且日志中没有错误

只有这样,

 public function calculate()
{
return $this->result(Kunde::count());
}

,但是范围不起作用。

1 个答案:

答案 0 :(得分:0)

也许有人遇到相同的问题..所以答案是:

metrics查询正在数据库中寻找created_at列,因此它必须有一个日期

指标查询就是这样。

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

:)