KoolReport's Forum

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

Dashboard in Laravel plus CSRF #1824

Closed esoft opened this topic on on Jan 7 - 20 comments

esoft commented on Jan 7

Dear Team,

can u guide me on how to configure the dashboard with laravel 5.8.

kindly share the related documents with me

kind regards

Qamar Aamir

KoolReport commented on Jan 7

Please create a folder "Dashboard" to hold the dashboard 's file like App.php or HomeDashboard.php the same like in the our dashboard-demo's src folder.

Please create an action in laravel controller, make sure it has GET and POST right. In this action, you will initiate the dashboard:

require_once "/path/to/Dashboard/App.php";
\demo\App::create()->run();

And that's all.

Andre Van Der Walt commented on Jan 14

When i run the dashboard with the example code, i get an

ErrorException: Undefined index: in vendor/koolreport/dashboard/Application.php:220

I'm also using laravel.

In my controller i have,

 public function dashboardReport()  
    {
        $report = new App();
        $report::create();
        $report->run();

    }

and in the app.php

class App extends \koolreport\dashboard\Application
{

    protected function dashboards()
    {
        return [
            "PaymentBoard"=> PaymentBoard::create()->icon("fa fa-home"),
        ];
    }

}

the rest of the code is as is on the quick start example.

Andre Van Der Walt commented on Jan 14

Would i need to render the dashboard in any blades like the reports?

KoolReport commented on Jan 14

@Andre: The code in laravel controller should be:

 public function dashboardReport()  
    {
        App::create()->run();
    }

You do not need to render dashboard in the blade like KoolReport

Andre Van Der Walt commented on Jan 15

This still has the same error with the above code.

Andre Van Der Walt commented on Jan 15

Here is full code:

//controller
  public function dashboardReport() 
    {
        App::create()->run();

    }

//app.php

class App extends \koolreport\dashboard\Application
{

    protected function dashboards()
    {
        return [
            "PaymentBoard"=> PaymentBoard::create()->icon("fa fa-home"),
        ];
    }

}

//paymentboard.php

use \koolreport\dashboard\Dashboard;

class PaymentBoard extends Dashboard
{

    protected function widgets()
    {
        return [
            PaymentTable::create(),
        ];
    }
}

//paymenttable.php

class PaymentTable extends Table
{
    protected function dataSource()
    {
        return AutoMaker::table("payments");

}

    protected function fields()
    {
        return [
            Date::create("paymentDate"),

            Currency::create("amount")
                ->USD()
                ->symbol(),
        ];
    }
}

//automaker.php

use koolreport\dashboard\sources\MySQL;

class AutoMaker extends MySQL
{
    protected function connection()
    {
        return [
            "connectionString" => "mysql:host=sampledb.koolreport.com;dbname=automaker",
            "username" => "expusr",
            "password" => "koolreport sampledb",
            "charset" => "utf8"
        ];
    }
}

//web.php

Route::get('/DashboardReport', 'ReportsController@dashboardReport');

also tried

Route::any('/DashboardReport', 'ReportsController@dashboardReport');
KoolReport commented on Jan 15

Thank you for posting your code, we found that our quick start code has a small bug so we have updated it

https://www.koolreport.com/docs/dashboard/quick_start/

Could you please try to copy the updated code to your code base one more time.

Please let me know if issue is gone.

Andre Van Der Walt commented on Jan 15

Thanks for the response

Code is working !!

KoolReport commented on Jan 15

That's great :)

KoolReport commented on Jan 15

By the way, we have a lot of example in our dashboard-demo that you may have a look.

Andre Van Der Walt commented on Jan 15

For the dashboard demo, i seem to get an error with the csrf token like below. it happens on the navbar items

KoolReport commented on Jan 15

@Andre: The csrf token is not supported yet in Dashboard, sorry for that. But we will release new version soon with this feature as it is critical. For now, could you please try to disable the csrf for dashboardReport route.

KoolReport commented 5 days ago

Great news on Laravel CSRF, we have released new version of Dashboard (1.3.5) which will work with Laravel CSRF.

To make dashboard work with laravel csrf, you do like this in laravel controller

public function dashboardReport() 
{
    App::create()
    ->csrf(
        \koolreport\dashboard\security\CSRF::create()
        ->token(function(){
            return csrf_token();
        })
    )
    ->run();
}

Basically, you will create a CSRF object which token is created by laravel's token generated function csrf_token().

Hope that helps.

Andre Van Der Walt commented 5 days ago

Excellent news. Thank you

KoolReport commented 5 days ago

@Andre: Please test the new version of Dashboard with your laravel app, let us know if it works.

Andre Van Der Walt commented 5 days ago

Hi Guys, i still get the same error even after updating the packages and adding the code

public function dashboardReport() 
{
    App::create()
    ->csrf(
        \koolreport\dashboard\security\CSRF::create()
        ->token(function(){
            return csrf_token();
        })
    )
    ->run();
}
KoolReport commented 5 days ago

Really, hmm, let me inform dev.team. May I know your version of PHP and Laravel. We will test on the same version as you have.

Note: Please make sure you have install Dashboard 1.3.5 and important clear all folder "public\koolreport_assets" if there is. Please try to refresh Crtl + F5 as well since to make this work, it requires new javascript file, and sometime due to caching, the file is not updated.

Also, if possible, please open the console of browser and let me know if there is any error showing. If there is, please let me know.

KoolReport commented 5 days ago

By the way, we tested on PHP 7.3 and Laravel 5.8, it worked great. I have seen documentation for new version of laravel and they are working in the same ways. Looking forward to hearing from you.

Andre Van Der Walt commented 3 days ago

Hi Guys, i've responded on email in detail with my issue. The CSRF token mismatch is resolved after clearing the koolreport_assets directory.

Php version 7.4 and laravel version 6.2

Branden

KoolReport commented 3 days ago

Perfect :D

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
solved

Dashboard