KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Simple Table in Laravel #241

Open William opened this topic on on Apr 7, 2018 - 3 comments

William commented on Apr 7, 2018

Hi, I am trying to create a simple table using Laravel. I am new to KoolReport, but I've used it to create other reports. I've found a very few posts here about using KoolReport with Laravel, but they didn't help me solve my problem.

Here are my files:

--- \routes\web.php (routes file) ---

Route::get('/report/table', 'ReportsController@table');

--- \app\Http\Controllers\ReportsController.php ---

namespace App\Http\Controllers;
class ReportsController extends Controller
{
	public function table()
	{
		$table = new \App\Reports\Table;
		$table->run();
		return view('table', compact('table'));
	}
}

--- \app\Reports\Table.php ---

<?php
namespace App\Reports;
use koolreport\KoolReport;
//require_once dirname(__FILE__)."/../../vendor/koolreport/autoload.php"; // No need, if you install KoolReport through composer
class Table extends KoolReport
{
	function settings()
	{
		return array(
			"dataSources" => array(
				"mydata" => array(
					'connectionString' => 'pgsql:host=localhost;port=5500;dbname=tc'
					,'username' => 'postgres'
					,'password' => 'password'
				)
			)
		);
	}

	function setup()
	{
		$this->src("mydata")
			->query("select date(punch_timestamp) as punch_date, id_punch_type from punches")
			->pipe($this->dataStore("punches"));
	}
}

--- \resources\views\table.blade.php ---

<?php
use koolreport\widgets\koolphp\Table;
Table::create(array(
	"dataStore" => $table->dataStore("punches")
));
?>

Here's the exception I keep receiving:

Undefined index: __ACTIVE_KOOLREPORT__ (View: /var/www/html/rpta/webapp/resources/views/table.blade.php)

in /var/www/html/rpta/webapp/vendor/koolphp/koolreport/koolreport/core/Widget.php

 public function __construct($params=null)
    {
        $this->params = $params;
        $this->report = $GLOBALS["__ACTIVE_KOOLREPORT__"]; <--- this line is highlighted
        $this->currentDir = dirname(Utility::getClassPath($this));
        $this->name = Utility::get($this->params,"name");

When I follow the exception trace back a few files, it identifies file table.blade.php / Table::create... commmand.

What am I missing?

KoolReport commented on Apr 9, 2018

The view file of KoolReport is different from view file of Laravel. So you have to create a Table.view.php in the same folder with Table.php in Reports folder. Inside the Table.view.php, you will place the Table widget.

Then in the view of laravel, you will called

<?php $report->render(); ?>

Note that the $report ->render() will return HTML not Blade template so you may need to cover the render() function.

{!! <?php $report->render(); ?> !!}
William commented on Apr 9, 2018

Thanks for your reply. I tried for several days to get this working before sending the email, but I figured it out soon after sending it, before you were able to respond. There were a lot of problems with my code. :)

anurag commented on Apr 16, 2019

How can i download in excel format

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None