簡體   English   中英

使用 Laravel Nova 顯示指標趨勢的問題 - 參數太少

[英]Issue displaying Metrics Trend with Laravel Nova - Too few arguments

因此,我嘗試向資源添加新的指標趨勢,但總是收到以下錯誤:

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

趨勢指標只是不斷加載,就像它不可用於檢索數據一樣。

countByDays函數的第二個參數是model類而不是 Nova resource類。

更新以下 use 語句use App\Nova\Reportuse App\Report

我有同樣的問題,只需更改 use App\Nova\Report; 使用 App\Report; 一切都會好起來的。 來自 php storm 的建議太奇怪了 xD

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM