I followed the guide on https://charts.erik.cat/guide/ to install Chartisan with echarts in my Laravel 7.4 framework. Everything works fine and I receive a chart.
The chart is triggered with this handler function:
public function handler(Request $request): Chartisan
{
return Chartisan::build()
->labels(['First', 'Second', 'Third'])
->dataset('Sample', [1, 2, 3])
->dataset('Sample 2', [3, 2, 1]);
}
The dataset shall be pulled from my database therefore I modify the code to:
public function handler(Request $request): Chartisan
{
$data = DB::Users->where('id',$id)->find(1); //$id is not defined
return Chartisan::build()
->labels(['First', 'Second', 'Third'])
->dataset('Sample', [1, 2, 3])
->dataset('Sample 2', [3, 2, 1]);
}
Of course this doesn't work because $id is not defined. How and where can I pass data to the handler function? How can I use the $request variable if it is not a form?
The chart is called via the api/chart/SampleChart route. Where is this route defined? Could I pass data to the route? It is not included in routes/api.php or web.php.
All Laravel/Chart examples with the handler function are using ALL data from the database table without restrictions. I did not find an example which passes data.
global $id does not work to get access to $id.