coroo / nova-chartjs

A Simple Dashboard Chart in Laravel Nova using Chart JS. Starting create your own dashboard with Chart JS Integration can save your time and help you maintain consistency across standard elements such as Bar, Stacked, Line, Area, Doughnut and Pie Chart.
https://coroo.github.io/nova-chartjs
MIT License
215 stars 72 forks source link

[BUG] json_decode(): Argument #1 ($json) must be of type string, array given #169

Closed ndberg closed 1 year ago

ndberg commented 1 year ago

Describe the bug Out of nowhere I get an error:

json_decode(): Argument #1 ($json) must be of type string, array given
array:2 [▶
  "userId" => 1
  "exception" => TypeError {#1602▶
    #message: "json_decode(): Argument #1 ($json) must be of type string, array given"
    #code: 0
    #file: "/var/www/backend/vendor/coroowicaksono/chart-js-integration/src/api/TotalRecordsController.php"
    #line: 26
    trace: {▶}
  }
]

To Reproduce Steps to reproduce the behavior:

  1. Add a Chart
  2. Add anything to the options array, like: ->options(['uom' => 'day',])

As soon as any option is present, the error shows up. It looks like the NovaRequest $request->options[] changed from json to array? But couldn't find a change like this in the Nova releases.

Does anybody else have this error?

Dependencies Version:

bmellink commented 1 year ago

I have the same issue. It seems laravel/nova has a breaking change between versions 4.29.5 and 4.29.6 that impacts nova-chartjs. Temporary work around is to change your composer.json to downgrade laravel/nova. Change the line that reads

"laravel/nova": "~4",

to

"laravel/nova": "4.29.5",

This will force using the laravel/nova version that is still compatible with nova-chart-js. I hope it will be fixed soon in nova-chart-js. The issue is in TotalRecordsController.php function handle() where $request->options used to be passed as a json string and with the new version of laravel/nova are passed as array, so all the json_decode() commands generate exceptions.

ndberg commented 1 year ago

You're right, it works with laravel/nova v4.29.5.

Thanks for helping

coroo commented 1 year ago

Release new version 0.4.2. Hopefully can help to fix the error for laravel nova 4.31.x https://github.com/coroo/nova-chartjs/releases/tag/v0.4.2