I can not perform this insertion even in an array, considering that I have this static array of example in php. Where I intend to visualize the record in a bar graph with the canvasjs library, where one of its attributes is to pass an array like the following:
$dataPoints = array(
array("label"=> "Matematicas", "y"=>22),
array("label"=> "Ingles", "y"=> 34),
array("label"=> "Fisica", "y"=> 4),
array("label"=> "Quimica", "y"=> 13),
array("label"=> "Arte", "y"=> 50)
);
This part is done in the controller (by the way I'm working with laravel) but now I want to get the data from a database. This is my method of my controller
public function index()
{
$dataPoints= DB::table('materias')->get();
return View('reporteMaterias',compact('dataPoints'));
}
Now, if I pass the static array and charge it to the canvarjs in one of its parameters in this way it works correctly:
data: [{
type: "column",
showInLegend: true,
legendMarkerColor: "grey",
legendText: "Materias ",
dataPoints: @json($dataPoints)
}]
});
So, going back to the main point, how would you make a dynamic array but query the database to be dynamic? if taking into account that this is my query $dataPoints= DB::table('materias')->get();
Now how do I pass it as the static array mentioned above?