Permission

Overview #

Although it is possible to set permission for dashboard and widget by using enabled() method with custom condition, it is very troublesome because of the repeated codes., for example:

class App extends Application
{
    protected function sidebar()
    {
        return [
            RevenueBoard::create()->enabled(function($request){
                return $request->user()->hasRole("manager");
            }),
            CostBoard::create()->enabled(function($request){
                return $request->user()->hasRole("manager");
            }),
        ];
    }
}

Permit #

To solve this issue, you can create your Permit class which derived from \koolreport\dashboard\Permit, for example:

<?php

class Permit extends \koolreport\dashboard\Permit
{
    protected function beManager($request, $sender)
    {
        return $request->user()->hasRole("manager");
    }
}

and then you can use register your Permit like below.

class App extends Application
{
    protected function permision()
    {
        return Permit::create();
    }

    protected function sidebar()
    {
        return [
            "Revenue Report" => RevenueBoard::create()->enabledWhen("beManager"),
            "Cost Report" => CostBoard::create()->enabledWhen("beManager"),
        ];
    }
}

Note that when you register Permit class with Application, you can use enabledWhen() with widgets as well, for example:

class SaleBoard extends Dashboard
{
    protected function content()
    {
        return [
            BriefTable::create(),
            DetailTable::create()->enabledWhen("beManager")
        ];
    }
}

Get started with KoolReport

KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.