Dashboard Item

Dashboard items are the three different types of items (top card, right sidebar, tab page) that are displayed on the home page after logging into the administration panel or member's area. You may create new dashboard items by using the create dashboard-item CLI command, such as:

apex create dashboard-item <PACKAGE> <ALIAS>

apex create dashboard-item my-shop total-orders

Using the above example, a new file will be created at /src/MyShop/Opus/DashboardItems/TotalOrders.php which contains only one method of render() and six properties. The properties are explained in the below table.

Property Description
$type The type of dashboard item, supported values are "top", "right" and "tab".
$area The area the dashboard item is assigned to. Generally will always be either "admin" or "members" unless custom areas have been developed into the system.
$is_default Boolean that defines whether or not to activate it on the default dashboard that all users see except those who have defined a custom dashboard for themselves.
title Title of the dashboard item.
$divid The div id of the item, which will line up with the necessary CSS for background color, et al.
$panel_clas Only applicable if the type is "top", and is the CSS class to assign.

Below is an example PHP class of a dashboard item.

<?php
declare(strict_types = 1);

namespace App\MyShop\Opus\DashboardItems;

use Apex\App\Interfaces\Opus\DashboardItemInterface;
use App\MyShop\Models\Order;

/**
 * Dashboard item - TotalOrders
 */
class TotalOrders implements DashboardItemInterface
{

    /**
     * The type of dashboard item.
     * Can be either:  top, right, tab
     */
    public string $type = 'top';

    /**
     * The area this dashboard item is available.  
     * Generally will only ever be either 'admin' or 'members'.
     */
    public string $area = 'admin';

    /**
     * Whether or not to activate this dashboard item upon initial installation
     */
    public bool $is_default = false;

    /**
     * The title of the dashboard item.
     */
    public string $title = 'Total Users';

    /**
     * The div id and panel class name of the dashboard item.
     * Only applicable for items with $type of 'top'.
     */
    public string $divid = 'members-online';
    public string $panel_class = 'panel bg-teal-400';


    /**
     * Render the dashboard item.
     *
     * @return The HTML contents of the dashboard item.
     */
    public function render():string
    {
        // Get total orders
        $total = Order::count('status = %s', 'approved');

        // Return
        return $total;
    }

}