Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ndberg opened this issue Jun 6, 2024 · 1 comment

Comments

@ndberg
Copy link

ndberg commented Jun 6, 2024

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)),
            ]),
        ];
    }
}
@davide-granello
Copy link

same issue here:

Versions:
laravel/framework: 11.27.2
laravel/nova: 4.35.3
digital-creative/nova-dashboard: 1.1.3
digital-creative/chartjs-widget: 1.0.2

Code:

<?php

namespace App\Nova\Widgets;

use DigitalCreative\ChartJsWidget\Charts\BarChartWidget;
use DigitalCreative\NovaDashboard\Filters;
use Illuminate\Support\Collection;
use Laravel\Nova\Http\Requests\NovaRequest;

class WidgetName 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(__('Number') . __('Name'));
    $this->buttonTitle('BarChart');
    $this->backgroundColor(dark: '#FFFFFF06', light: '#00000006');

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants