Skip to content

Can't get it to work - Call to a member function resolveWidgetValue() on null #14

@ndberg

Description

@ndberg

I tried to use your dashboard and followed your example Code, but I always get this error:

"message": "Call to a member function resolveWidgetValue() on null",
"exception": "Error",
"file": "/Volumes/Work/Code/platreform/backend/vendor/digital-creative/nova-dashboard/src/Http/Controllers/WidgetController.php",
"line": 20,

When I analyze the Code in the WidgetController on Line 20, it looks like it does not find the View

   // dump(View::findView($request)) // is always null

  return response()->json([
      'value' => View::findView($request)->resolveWidgetValue($request, $widgetKey), 
  ]);

Thanks for your Help!

Versions:
laravel/framework: 10.48.12
laravel/nova: 4.34.2
digital-creative/nova-dashboard: 1.1.3
digital-creative/chartjs-widget: 1.0.2

My Code:

class LeadsDashboard extends Dashboard
{
    /**
     * Get the displayable name of the dashboard.
     */
    public function label(): string
    {
        return 'Leads';
    }

    /**
     * Get the cards for the dashboard.
     */
    public function cards(): array
    {
        return [
            NovaDashboard::make()
                ->addView('Leads Example', function (View $view) {
                    return $view
                        ->icon('window')
                        ->addWidgets([
                            ExampleBarChartWidget::make(),
                        ])
                        ->addFilters([
                            DateRangeFilter::make()
                                ->dividerLabel('<>') // control the divider label in between the inputs
                                ->inputType('week') // supports any html input type
                                ->placeholder('From', 'To') // control the placeholder of the inputs
                                ->fromAttributes([ 'min' => 0 ]) // some inputs type like number accepts more attributes like min/max/step etc..
                                ->toAttributes([ 'max' => 100 ])
                        ]);
                }),
        ];
    }
}

class ExampleBarChartWidget extends BarChartWidget
{
    public function configure(NovaRequest $request): void
    {
        /**
         * These set the title and the button on the top-right if there are multiple "tabs" on this view
         */
        $this->title('Example BarChart');
        $this->buttonTitle('BarChart');
        $this->backgroundColor(dark: '#1e293b', light: '#ffffff');

        $this->padding(top: 30, bottom: 5);

        $this->tooltip([]); // https://www.chartjs.org/docs/latest/configuration/tooltip.html#tooltip
        $this->scales([]);  // https://www.chartjs.org/docs/latest/axes/#axes
        $this->legend([]);  // https://www.chartjs.org/docs/latest/configuration/legend.html#legend
        $this->elements();  // https://www.chartjs.org/docs/latest/configuration/elements.html#elements
    }

    public function value(Filters $filters): array
    {
        return [
            'labels' => Collection::range(0, 5)->map(fn () => fake()->word()),
            'datasets' => Collection::range(0, 5)->map(fn () => [
                'data' => Collection::range(0, 5)->map(fn () => fake()->numberBetween(0, 100)),
            ]),
        ];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions