Laravel: Jasper reports in laravel lumen5.6

I already implemented jasper reports with laravel and it works fine for me. Now i shifted to laravel lumen for api building so i try to integrate jasper as same as i integrate in my laravel projects but in laravel lumen it throws some error as below:-

Call to undefined method Laravel\Lumen\Application::booting()

below is my connection code

class_alias(JasperPHP\JasperPHPServiceProvider::class,'JasperPHP');
   $app->withFacades(); $app->withEloquent(); 
   $app->register(App\Providers\AppServiceProvider::class); 
   $app->register(App\Providers\AuthServiceProvider::class); 
   $app->register(App\Providers\EventServiceProvider::class); 
   $app->register(JasperPHP\JasperPHPServiceProvider::class);

Please share your thoughts, Thanks in advance

Upvotes: 0

Views: 987

Answers (1)

I finally come up with a solution and it works fine with laravel lumen 5.6 below are the steps:-
1)Install JasperReports 6 library by below command

composer require cossou/jasperphp

In bootstrap/app.php uncomment this line $app->withFacades(); and add below code

$app->singleton('jasperphp', function ($app) {
            return new JasperPHP;
        });
 $app->alias('JasperPHP\JasperPHPServiceProvider\JasperPHP', 'JasperPHP');

Controller part Changes

namespace App\Http\Controllers;
use JasperPHP\JasperPHP as JasperPHP;
use Illuminate\Http\Request;

//dd(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper');
class ReportController extends Controller {

    public function generateReport() {
        //JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
        $jasper = new JasperPHP;
        $filename = 'gau';
        $output = base_path('//public/reports/' . $filename);
        $jasper->process(
                base_path('/vendor/cossou/jasperphp/examples/LaravelIreporTest.jasper'), 
                $output,
                array("pdf"), 
                array("test" => "Tax Invoice"), 
                array(
                        'driver' => 'mysql',
                        'username' => 'username',
                        'password' => 'password',
                        'host' => 'localhost',
                        'database' => 'database name',
                        'port' => '3306',
                      )
        )->execute();
    }

}

Upvotes: 0

Related Questions