因此,我试图向资源中添加新的指标趋势,但始终会收到以下错误:
Too few arguments to function Laravel\Nova\Resource::__construct(), 0 passed in /crm/nova/src/Metrics/Trend.php on line 116 and exactly 1 expected {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Too few arguments to function Laravel\\Nova\\Resource::__construct(), 0 passed in crm/nova/src/Metrics/Trend.php on line 116 and exactly 1 expected at /crm/nova/src/Resource.php:108)
我正在尝试从数据库表“报告”中的“ ph_value”列接收数据。
<?php
namespace App\Nova\Metrics;
use Illuminate\Http\Request;
use Laravel\Nova\Metrics\Trend;
use App\Nova\Report;
class ph extends Trend
{
/**
* Calculate the value of the metric.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function calculate(Request $request)
{
return $this->countByDays($request, Report::class, 'ph_value');
}
/**
* Get the ranges available for the metric.
*
* @return array
*/
public function ranges()
{
return [
30 => '30 Days',
60 => '60 Days',
90 => '90 Days',
];
}
/**
* Determine for how many minutes the metric should be cached.
*
* @return \DateTimeInterface|\DateInterval|float|int
*/
public function cacheFor()
{
// return now()->addMinutes(5);
}
/**
* Get the URI key for the metric.
*
* @return string
*/
public function uriKey()
{
return 'ph';
}
}
当然包括卡。
public function cards(Request $request)
{
return [
new Metrics\Ph,
];
}
趋势指标会不断加载,就像无法获取数据一样。
答案 0 :(得分:1)
countByDays
函数的第二个参数是model
类,而不是Nova resource
类。
将使用声明use App\Nova\Report
之后的内容更新为 use App\Report
答案 1 :(得分:0)
我有同样的问题,只需更改使用App \ Nova \ Report;使用App \ Report;会没事的。来自PHP Storm的建议让xD很奇怪