3

So I'm trying to add a new Metric Trend to a Resource but always receive the following error:

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)

I'm trying to receive the data from the column 'ph_value' in the database table 'reports'.

<?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';
    }
}

Card is of course included.

public function cards(Request $request)
    {
        return [
          new Metrics\Ph,
        ];
    }

The trend metric just loads constantly like it isn't available to retrieve the data.

ugexe
  • 5,297
  • 1
  • 28
  • 49
David
  • 47
  • 6

2 Answers2

6

countByDays function's second parameter is a model class not Nova resource class.

Update following use statement use App\Nova\Report to use App\Report

Saumini Navaratnam
  • 8,439
  • 3
  • 42
  • 70
0

I have same issue, just change use App\Nova\Report; to use App\Report; and it'll be fine. Suggestion from php storm so weird xD