KoolReport's Forum

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

Need Help to configuration Dashboard on Laravel #3131

Open Valerio Valentini opened this topic on on Aug 29, 2023 - 8 comments

Valerio Valentini commented on Aug 29, 2023

Good evening, i bought the pro package and i'm trying to setup the dashboard on laravel.

These are the installed packages on my project

"koolreport/blade": "^1.0",
 "koolreport/dashboard": "^4.2",
 "koolreport/export": "^5.3",
 "koolreport/pro": "^6.2",
"laravel/framework": "^7.0",
"php": "^7.2.5"

the file structure is pretty much the same as the demo in the documentation, I would like to display the dashboard on the left as seen in the demos but I can't get it to work, even the theme seems to be static without css (style ), thanks in advance for your support, I report the code:

///////////////////////////////////////////////////////////////////

ReportController.php

///////////////////////////////////////////////////////////////////

<?php

namespace App\Http\Controllers;

use App\Reports\MyReport;
use Illuminate\Http\Request;

class ReportController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware("guest");
    }
    public function index()
    {
        // require_once  base_path(). '/vendor/autoload.php'; //Load library
        // require_once base_path(). '/Dashboard/App.php';

        // \App::create()->run();
         $report = new MyReport;
         $report->run();

         return view("report/report",["report"=>$report]);
    }
}

///////////////////////////////////////////////////////////////////

MyReport.php

///////////////////////////////////////////////////////////////////

<?php
namespace App\Reports;
use App\Models\User;

class MyReport extends \koolreport\KoolReport
{
    use \koolreport\laravel\Friendship;
    function settings()
    {
        return array(
            "dataSources"=>array(
                "elo"=>array(
                    "class"=>'\koolreport\laravel\Eloquent', // This is important
                )
            )
        );
    }
    function setup()
    {
        //Now you can use Eloquent inside query() like you normally do
        $this->src("elo")->query(
            User::orderBy('name', 'desc')
                ->take(10)
        )
        ->pipe($this->dataStore("users"));
    }
}

///////////////////////////////////////////////////////////////////
MyReport.view.php
///////////////////////////////////////////////////////////////////

<?php
use \koolreport\widgets\koolphp\Table;
?>
<html>
    <head>
    <title>My Report</title>
    </head>
    <body>
        <h1>It works</h1>
        <?php
        Table::create([
            "dataSource"=>$this->dataStore("users")
        ]);
        ?>
    </body>
</html>

///////////////////////////////////////////////////////////////////

report.blade.php

///////////////////////////////////////////////////////////////////

<?php $report->render(); ?>
KoolReport commented on Aug 30, 2023

In your MyReport class, let try this:

class MyReport extends KoolReport
{
    use \koolreport\clients\Bootstrap;
}
Valerio Valentini commented on Aug 30, 2023

Unfortunately it doesn't work, it doesn't seem to even take the basic style. I attach a screenshot.

Sebastian Morales commented on Aug 31, 2023

Is this the Dashboard framework or a single KoolReport report you were trying to implement? To check for css or javascript problem pls open browser's dev tool (F12) then reload the page to see if there's any css file loading or js error message in console.

Valerio Valentini commented on Sep 4, 2023

I took the code of the previous message from your site's Laravel documentation and the result is the screen I attached.

Now I tried to follow the Dashboard documentation but I have an error, I am attaching the code and a screen.

mylaravelproject

- Dashboard (folder)
   - App.php
   - AutoMaker.php
   - User.php
   - UserTable.php

Dashboard\App.php

<?php
//App.php

///Dashboard Classes
use \koolreport\dashboard\Application;
use \koolreport\dashboard\Client;

///Menus
use \koolreport\dashboard\menu\MenuItem;
use \koolreport\dashboard\menu\MegaMenu;
use \koolreport\dashboard\menu\Group;

///Themes
use \koolreport\amazing\dashboard\Amazing;
use \koolreport\appstack\dashboard\AppStack;

///Pages
use koolreport\dashboard\pages\Main;

///Languages
use koolreport\dashboard\languages\EN;
use koolreport\dashboard\languages\ES;
use koolreport\dashboard\languages\FR;
use koolreport\dashboard\languages\DE;
use koolreport\dashboard\languages\IT;



class App extends Application
{
    protected function sidebar()
    {
        return [
            "Utenti" => User::create()
        ];
    }

    protected function languages()
    {
        return [
            EN::create(),
            ES::create(),
            FR::create(),
            DE::create(),
            IT::create()
        ];
    }

    protected function topMenu()
    {
        return [
            "Simple link"=>MenuItem::create()
                ->href("https://www.anywebsite.com")
                ->target("_blank"),

            "With Icon and Badge"=>MenuItem::create()
                ->href("https://www.example.com")
                ->icon("fa fa-book")
                ->badge(["NEW","danger"]),

            "Execute javascript"=>MenuItem::create()
                ->onClick("alert('hola')"),

            "Mega Menu"=>MegaMenu::create()->sub([
                "Group 1"=>Group::create()->sub([
                    "Item 11"=>MenuItem::create(),
                    "Item 12"=>MenuItem::create(),
                ]),
                "Group 2"=>Group::create()->sub([
                    "Item 21"=>MenuItem::create(),
                    "Item 22"=>MenuItem::create(),
                ]),
            ]),

            "Disabled Item"=>MenuItem::create()->disabled(true),
        ];
    }

    protected function onCreated()
    {
         $this->debugMode(true)
         ->appKey(env('APP_KEY'))
         ->title("My Dashboard")
         ->logo("<b>My Dashboard</b>")
         ->favicon("images/superman.ico")
         ->footerLeft("Dashboard@KoolReport")
         ->footerRight("Powered by KoolReport")
         ->csrf(\koolreport\dashboard\security\CSRF::create())
         ->theme(AppStack::create());

    }
}


Dashboard\AutoMaker.php

<?php

use \koolreport\dashboard\sources\MySQL;

class AutoMaker extends MySQL
{
    protected function connection()
    {
        return [
            "connectionString"=>"mysql:host=127.0.0.1;dbname=geco-lms",
            "username"=>"root",
            "password"=>"root",
            "charset"=>"utf8"
        ];
    }
}

Dashboard\User.php

<?php

use \koolreport\dashboard\Dashboard;

class User extends Dashboard
{
    protected function content()
    {
        return [
            UserTable::create()
        ];
    }
}

Dashboard\UserTable.php

<?php

use \koolreport\dashboard\widgets\Table;
use \koolreport\dashboard\fields\Currency;
use \koolreport\dashboard\fields\DateTime;

class UserTable extends Table
{
    protected function dataSource()
    {
        return AutoMaker::table("users")->limit(10);
    }

    protected function fields()
    {
        return [
            DateTime::create("created_at")
                ->displayFormat("M jS, Y"),

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

ReportController.php

<?php

namespace App\Http\Controllers;

use App\Reports\MyReport;
use Illuminate\Http\Request;

class ReportController extends Controller
{
    //
    public function __construct()
    {
        $this->middleware("guest");
    }
    public function index()
    {
         require_once  base_path(). '/vendor/autoload.php'; //Load library
         require_once base_path(). '/Dashboard/App.php';

        return \App::create()->run();
         // $report = new MyReport;
         // $report->run();
          //\App::create()->run();

         // return view("report/report",["report"=>$report]);
    }
}


SCREENSHOT - Now I see everything correctly, the problem is that I entered everything in a very simple Get Route which returns me with a KDR parameter with a token.. and when I try to click on "Utenti" it gives me the error in screen.

LINK - http://localhost:8000/report?kdr=eyJyb3V0ZSI6IkFwcC9NYWluL1VzZXIiLCJhY3Rpb24iOiJpbmRleCIsInBhcmFtcyI6bnVsbH0=

SCREEN 1 & SCREEN 2.

What am I doing wrong? What am i missing?

SCREEN 1

SCREEN 2

Sebastian Morales commented on Sep 5, 2023

In your Laravel's route file (routes/web.php) enable post method for the route to your dashboard page (/report) similarly to the get method for that route.

Valerio Valentini commented on Sep 5, 2023

Many thanks for the help, now it seems to work without errors, I also added the token as it gave me error.

However, is the link set with this parameter part of how the dashboard framework works?

http://localhost:8000/report?kdr=eyJyb3V0ZSI6IkFwcC9NYWluL1VzZXIiLCJhY3Rpb24iOiJpbmRleCIsInBhcmFtcyI6bnVsbH0=

because it shows it by default when i reach the page.

Thank you

Sebastian Morales commented on Sep 6, 2023

Yes, the kdr get parameter part after the route is required for Dashboard to persist its state across user actions.

Valerio Valentini commented on Sep 7, 2023

Very clear, thank you so much for the support

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