KoolReport's Forum

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

Use KoolReport in laravel #147

Open usman opened this topic on on Nov 6, 2017 - 13 comments

usman commented on Nov 6, 2017

How KoolReport package be used in laravel framework?I have tried but there is no explanation anywhere.

KoolReport commented on Nov 6, 2017

KoolReport can be used in Laravel or any MVC frameworks. You create report from KoolReport normally as you do. Then to start the report in Laravel you do:

Route::get('/testreport', function(){
    $report = new SaleReport;
    $report->run();
   return view('testreport',["report"=>$report]);
});

At the view of Laravel:

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

Let me know if you need further assistance.

usman commented on Nov 6, 2017

and where to place koolreport folder in laravel framework?

KoolReport commented on Nov 6, 2017

Put it inside "vendor" folder "vendor/koolreport"

Folder for your reports can be put inside "app" folder.

KoolReport commented on Nov 7, 2017

Here is the step to setup KoolReport in Laravel:

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";

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.

usman commented on Nov 7, 2017

Thankyou.

vongsi commented on Nov 18, 2017

Thanks for the tutorial, it helped me.

Appreciated

KoolReport commented on Nov 18, 2017

You are welcome :) anything please let us know.

fahad commented on Mar 15, 2019

Hi every one hope all are fine. The above all configuration are showing one report config but if i need more than one report so how to manage ? should i create another controller, view file or we can make another method in same controller ?

fahad commented on Mar 15, 2019

I have created one report using koolreport but i am confusing for second report

KoolReport commented on Mar 15, 2019

It is totally up to you. KoolReport helps you to create a report object purely process data and return result. You may create another method to show report or you tweak current method to receive parameters and show correct report.

fahad commented on Mar 15, 2019

i have a report.php class with method1 and has view file report.view.php but now i need to make method2 in same class but which view file i will use and how to call like report1.view.php please help

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

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

class MyReport extends \koolreport\KoolReport
{
    function method1(){
     report.view.php /// how view file call by name
    }
    
    function method2(){
        report1.view.php /// how view file call by name
    }
}
KoolReport commented on Mar 16, 2019

Fahad,

KoolReport does not have separate methods in controller so basically you create another report. For example you may have SaleReport.php, CustomerReport.php.. each report has its own data connection, processing and visualization. If you need to use the same data connection for all report. You may create a BaseReport.php in which you have your connection in setup() function and all other reports will derive from it. If you use the \koolreport\laravel\Friendship then your report can use Laravel database directly, you may not need the BaseReport like I suggested.

fahad commented on Mar 16, 2019

You mean every report has its own controller class and its view file like

### First report
saleReport.php /// class
saleReport.view.php //view file
### Second report
stockReport.php ///class
stockReport.view.php ///view file

your mean like above ?

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