I'm pretty new with KoolReport. I'm using it in my app to generate some cool charts. The problem I'm having is that the "dataStore" shows all the rows from the DB in the view even when the query returns only one. I'm using the Eloquent data source to get the data.
MyReport.php file:
use App\Models\Stage;
use App\Models\Resources;
class MyReport extends \koolreport\KoolReport
{
use \koolreport\laravel\Friendship;
use \koolreport\clients\Bootstrap;
function settings()
{
return array(
"dataSources"=>array(
"mysql"=>array(
"class"=>'\koolreport\laravel\Eloquent', // This is important
)
)
);
}
function setup(){
// finds only one row
$this->src("mysql")->query(
Stage::find($this->params["id"])
)
->pipe($this->dataStore("stageDef"));
$this->src("mysql")->query(
Resources::select('resourceName as Object name', 'amount as Amount in warehouse')
->join('warehouses', 'warehouses.warehouseId', '=', 'resources.resources_warehouseId')
->join('stages', 'stages.id', '=', 'warehouses.warehouseLocation')
->where('stages.id', '=', $this->params["id"])
)
->pipe($this->dataStore("resources"));
}
}
MyReport.view.php file:
<?php
use \koolreport\widgets\koolphp\Table;
?>
<html>
<head>
<title>Inventory</title>
</head>
<body>
<!-- shows the "name" from the result of the query on MyReport.php file -->
<?php
$data = $this->dataStore("stageDef");
foreach($data as $d){
echo (string) $d['name']
}
?>
<?php
\koolreport\widgets\google\BarChart::create(array(
"dataSource"=>$this->dataStore("resources")
))
?>
<?php
Table::create([
"dataSource"=>$this->dataStore("resources")
]);
?>
</body>
</html>
So, the thing is that the "dataStore("stageDef")" should only display one row, as you can see the query only fetches one row from the from DB, but in the view all the rows are displayed, I don't really know what is wrong, the "foreach" loop is the only way I have found to display the data I need, that is the reason of that loop on the view. The other "dataStore" works fine. Other thing I have tried is change the query for:
Stage::where('stages.id', '=', $this->params["id"])->first()
but is the same result.
Any help is appreciated.