KoolReport's Forum

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

Use of eloquent models instead of raw queries #732

Open BDO India LLP opened this topic on on Mar 7, 2019 - 3 comments

BDO India LLP commented on Mar 7, 2019

Hello, I'm integrating koolreport with Laravel framework. I'm using eloquent to fetch data. I've created an eloquent accessors, but I can't use those fields. Can I use the same for reporting instead of raw queries? Like instead of using following approach

<?php
namespace App\Reports;

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    function setup()
    {
        $this->src("sale_database")
        ->query("SELECT * FROM offices")
        ->pipe($this->dataStore("offices"));        
    }
}

can I use something like this?

<?php
namespace App\Reports;

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    function setup()
    {
        $this->src("sale_database")
        ->query(Model::all())
        ->pipe($this->dataStore("offices"));        
    }
}
KoolReport commented on Mar 7, 2019

Currently it is not possible. The future solution could be we will create a new datasource in laravel package which is able to receive above eloquent and pipe data. I will mark this post as a suggestion for next enhancement.

Matthew Flood commented on Nov 25, 2019

Is this available yet? I noticed the docs say "Actually you can feed any Collection of Laravel to the "dataSource" of KoolReport's widget to get them visualize."

KoolReport commented on Nov 26, 2019

@Matthew: The feature of using eloquence object is not yet available but the widgets of koolreport can receive data from laravel's Collection. Feeding "dataSource" of widget with laravel's querybuilder will work.

Not forget to mention, the querybuilder package works very similar to laravel's querybuilder so you can use querybuilder as alternative for now.

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
suggestion

Laravel