使用Laravel Nova显示指标趋势的问题-参数太少

时间:2019-04-12 17:39:06

标签: php laravel laravel-nova

因此,我试图向资源中添加新的指标趋势,但始终会收到以下错误:

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,
        ];
    }

趋势指标会不断加载,就像无法获取数据一样。

2 个答案:

答案 0 :(得分:1)

countByDays函数的第二个参数是model类,而不是Nova resource类。

将使用声明use App\Nova\Report之后的内容更新为 use App\Report

答案 1 :(得分:0)

我有同样的问题,只需更改使用App \ Nova \ Report;使用App \ Report;会没事的。来自PHP Storm的建议让xD很奇怪