# Dashboard

# What are the available lenses?

<table border="1" id="bkmrk-key-class-permission" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col></colgroup><tbody><tr><td>**Key**  
</td><td>**Class**  
</td><td>**Permission**  
</td></tr><tr><td>`revenue-lens`  
</td><td>`Aero\Admin\Lenses\RevenueLens`</td><td>`reports.orders`</td></tr><tr><td>`average-order-value-lens`  
</td><td>`Aero\Admin\Lenses\AverageOrderValueLens`</td><td>`reports.orders`</td></tr><tr><td>`top-shipping-countries-lens`  
</td><td>`Aero\Admin\Lenses\TopShippingCountriesLens`</td><td>`reports.orders`</td></tr><tr><td>`return-rate-lens`  
</td><td>`Aero\Admin\Lenses\ReturnsRateLens`</td><td>`reports.orders`</td></tr><tr><td>`orders-lens`  
</td><td>`Aero\Admin\Lenses\OrdersLens`</td><td>`reports.orders`</td></tr><tr><td>`top-selling-manufacturers-lens`  
</td><td>`Aero\Admin\Lenses\TopSellingManufacturersLens`</td><td>`reports.catalog`</td></tr><tr><td>`top-selling-items-lens`  
</td><td>`Aero\Admin\Lenses\TopSellingItemsLens`</td><td>`reports.catalog`  
</td></tr></tbody></table>

<p class="callout info">The default dashboard lenses are stored in the `admin` configuration file, inside the `dashboard_lenses` array.</p>

# How do I create a custom dashboard lens?

To create a dashboard lens you need to create a class that extends `Aero\Admin\AdminLens` and implement the `data` method:

```php
class OrdersLens extends \Aero\Admin\AdminLens
{
    protected $title = 'Orders';

    protected static $permission = 'reports.orders';

    protected static $dateGetVariables = [
        'custom' => 'ordered-at-date',
        'start' => 'ordered-at-date-start-date',
        'end' => 'ordered-at-date-end-date',
    ];

    public function data(\Illuminate\Http\Request $request, array $date, array $compare): \Illuminate\Http\JsonResponse
    {
        $ordersCount = \Aero\Cart\Models\Order::visible()->whereBetween('ordered_at', [$date['start'], $date['end']])->count();
        $ordersCompareCount = \Aero\Cart\Models\Order::visible()->whereBetween('ordered_at', [$compare['date']['start'], $compare['date']['end']])->count();

        if ($ordersCompareCount !== 0) {
            $percentage = (($ordersCount - $ordersCompareCount) / ($ordersCompareCount > 0 ? $ordersCompareCount : 1)) * 100;
        }

        return response()->json([[
            'text' => number_format($ordersCount),
            'compare' => [
                'text' => $ordersCompareCount === 0 ? 'No data to compare' : $compare['text'],
                'percentage' => isset($percentage) ? ($percentage >= 0 ? '+' : '') . number_format($percentage, 2) . '%' : '',
                'up' => isset($percentage) ? $percentage >= 0 : '',
            ],
        ]]);
    }

    protected function link(): ?array
    {
        return auth()->user()->can('reports.view') ? [
            'route' => route('admin.report', ['key' => 'order-breakdown']),
            'text' => 'View Report',
        ] : null;
    }
}
```

---

### Parameters

<table border="1" id="bkmrk-parameter-type-descr" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col><col style="width: 33.3731%;"></col></colgroup><tbody><tr><td>**Parameter**</td><td>**Type**</td><td>**Description**</td></tr><tr><td>`$request`  
</td><td>`\Illuminate\Http\Request`  
</td><td>The current request.</td></tr><tr><td>`$date`  
</td><td>`array`  
</td><td>Contains the selected `start` &amp; `end` dates.</td></tr><tr><td>`$compare`  
</td><td>`array`  
</td><td>Contains the compare `date` (`start` &amp; `end` nested instead) and the `text`.</td></tr></tbody></table>

# How do I add a custom dashboard lens to the dashboard?

First, you must register your lens:

```php
\Aero\Admin\Facades\Admin::registerLens(\Aero\Admin\Lenses\OrdersLens::class);
```

Then you can add it to the Dashboard:

```php
\Aero\Admin\Http\Responses\AdminDashboardPage::extend(function (\Aero\Admin\Http\Responses\AdminDashboardPage $page, \Closure $next) {
    // Add it as the first lens
    $page->addLens(
        \Aero\Admin\Lenses\OrdersLens::key(),
        \Aero\Admin\Lenses\OrdersLens::class
    );

    // Add it after a specific lens
    $page->addLensAfter(
        \Aero\Admin\Lenses\OrdersLens::key(),
        \Aero\Admin\Lenses\OrdersLens::class,
        \Aero\Admin\Lenses\RevenueLens::key()
    );

    // Add it before a specific lens
    $page->addLensBefore(
        \Aero\Admin\Lenses\OrdersLens::key(),
        \Aero\Admin\Lenses\OrdersLens::class,
        \Aero\Admin\Lenses\AverageOrderValueLens::key()
    );
});
```

# How can I remove an existing lens from the dashboard?

You can remove an existing lens by using the `removeLens()` method and passing the `key` of the lens you want to remove:

```php
\Aero\Admin\Http\Responses\AdminDashboardPage::extend(function (\Aero\Admin\Http\Responses\AdminDashboardPage $page, \Closure $next) {
    $page->removeLens(
        \Aero\Admin\Lenses\OrdersLens::key()
    );
});
```