KoolReport's Forum

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

How to use KoolReport in Laravel? #150

Closed KoolReport opened this topic on on Nov 7, 2017 - 14 comments

KoolReport commented on Nov 7, 2017

Lavavel is a poweful and widely used PHP MVC Framework. Like other MVC frameworks, KoolReport can work well with Laravel too. Previously we have written guide to integrate KoolReport into Yii and CodeIgniter. In this wiki, we guide you to integrate KoolReport into Laravel. So below are the steps to install and get started:

Step 1 Download KoolReport

Step 2 Unzip and copy koolreport folder into vendor folder under your laravel project.

Step 3 In folder app, create folder name "Reports"

Step 4 Create MyReport.php and MyReport.view.php with following content:

<?php
//MyReport.php
namespace App\Reports;

require_once dirname(__FILE__)."/../../vendor/koolreport/autoload.php"; // No need, if you install KoolReport through composer

class MyReport extends \koolreport\KoolReport
{
    //We leave this blank to demo only
}
<!-- MyReport.view.php -->
<html>
    <head>
    <title>My Report</title>
    </head>
    <body>
        <h1>It works</h1>
    </body>
</html>

Step 5 In your folder app/Http/Controllers create ReportController.php with following content:

<?php
// ReportController.php
namespace App\Http\Controllers;

use App\Reports\MyReport;

class ReportController extends Controller
{
    public function __contruct()
    {
        $this->middleware("guest");
    }
    public function index()
    {
        $report = new MyReport;
        $report->run();
        return view("report",["report"=>$report]);
    }
}

Step 6 In the resources/view, you add report.blade.php with following content:

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

Step 7 In your routes/web.php, you add the route to ReportController@index

Route::get('/report', "ReportController@index");

All done! Now if you go to "http://localhost/yourlaravelproject/public/report", you will see the page "It works" meaning that KoolReport has been running.

If you have any questions, please let us know.

Molese commented on Mar 18, 2018

I'm getting an error

FatalErrorException main(): Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/sat-sa-specialist/reporting/app/Reports/../../vendor/koolreport/autoload.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php')

in MyReport.php (line 5)

KoolReport commented on Mar 18, 2018

Just make sure that you include the "autoload.php" file of koolreport. Could you please check the path for require function.

One question: How do you install KoolReport? via download and copy to vendor folder? or via composer?

Molese commented on Mar 19, 2018

I installed via composer. The vendor folder is on the root directory same level as app folder. I have my laravel in the same vendor folder and laravel was also installed via composer.

KoolReport commented on Mar 19, 2018

I see, could you please remove the

require_once dirname(__FILE__)."/../../vendor/koolreport/autoload.php";

inside MyReport.php since composer is supposed to load KoolReport already if you installed through composer.

Molese commented on Mar 24, 2018

Works, thanks.

William commented on Apr 5, 2018

Thank you for your instructions on using KoolReport with Laravel. I have set it up successfully, but I have a few suggestions to make it easier for others.

For Step 5 / ReportController.php, change public function __contruct() to public function __construct().

For Step 6 / report.blade.php, change "resources/view" to "resources/views".

Optionally, for Step 6 / report.blade.php, change <?php echo $report->render(); ?> to {{ $report->render() }}. The echo command works, but the command in double braces ({{ / }}) is very familiar to blade users.

Optionally, for Step 7 / http://localhost/yourlaravelproject/public/report, instruct your users they may need to remove /public, so the URL becomes http://localhost/yourlaravelproject/report.

Again, thank you!

ike commented on Jan 25, 2019

I'm currently stuck implementing export to PDF in laravel.

Can you please share how to implement export to PDF package in laravel.

Thank you.

KoolReport commented on Jan 26, 2019

Hi ike, what have you done so far now?

ike commented on Jan 27, 2019

Whenever I use phantomjs is like so, I get a blank pdf page

$report = new Report();
$report->run()
            ->export()
            ->settings(array(
                     "useLocalTempFolder"=>true,
                     "phantomjs" => base_path('vendor/koolphp/koolreport/packages/export/bin/phantomjs'),
                     "resourceWaiting" => 2000,
              ))->pdf()->saveAs("../storage/myreport.pdf");

But whenever i switch to chromeBinary like so, i get nice pdf of my 404 error page, meaning its able to export my error page contents but not my report template

 $report = new Report();
 $report->run()
            ->export()
            ->pdf(array(
                  "chromeBinary" => 'C:\Program Files (x86)\Google\Chrome\Application\chrome'
            ))->saveAs("../storage/myreport.pdf");

Please help.

kelvin commented on Jul 24, 2019

Following above steps: In MyReport.php file I am getting an error: "Class 'koolreport\KoolReport' not found" Installed koolreport through composer.

<?php
 
namespace App\Reports;
 
 
class MyReport extends \koolreport\KoolReport {
 
    use \koolreport\laravel\Friendship;
}
venkyp commented on Oct 23, 2019

Installed koolreport through composer Laravel 5.4.

When I try to follow your steps i get msg like this.

Whoops, looks like something went wrong.
1/1 FatalErrorException in MyReport.php line 4: Class 'koolreport\KoolReport' not found
in MyReport.php line 4
KoolReport commented on Oct 23, 2019

Please send me the code where you create the MyReport object. Is it inside Laravel controller?

usmsn commented on Jan 12, 2020

I am getting a blank page in laravel

Mahesh Lowe commented on Jun 2, 2021

This works well. Thanks.

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
wiki

None