Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Sharp Laravel Package

code16/sharp

Code-driven CMS framework for Laravel (PHP 8.3+/Laravel 11+). Build admin/CMS sections with a clean UI and strong DX: CRUD with validation, search/sort/filter, bulk or custom commands, and authorization—no front-end code required, data-agnostic.

View on GitHub
Deep Wiki
Context7

Dashboard

Class: Code16\Sharp\Show\Fields\SharpShowDashboardField.

The field allows you to integrate a Dashboard into your Show Page.

Constructor

This field needs, as first parameter, either the entity key or the SharpDashboardEntity class that declares the dashboard which will be included in the Show Page.

For instance:

SharpShowDashboardField::make('posts_dashboard')

or

SharpShowDashboardField::make(PostDashboardEntity::class)

::: warning This last syntax is better in terms of DX (since it allows using the IDE to navigate to the Entity List implementation), but it won’t work in two specific cases: if you use a custom SharpEntityResolver or if you your Entity is declared with multiple keys. :::

Configuration

hideFilterWithValue(string $filterName, $value)

This is the most important method of the field, since it will not only hide a filter but also set its value. The purpose is to allow to scope the data to the instance of the Show Page. For example, let’s say we display a Post and that we want to embed a dashboard with the post's statistics:

class PostShow extends SharpShow
{
    // ...
    
    public function buildShowFields(FieldsContainer $showFields): void
    {
        $showFields->addField(
            SharpShowDashboardField::make(PostDashboardEntity::class)
                ->hideFilterWithValue(PostFilter::class, 64)
        );
    }
}

Here we're scoping the PostDashboard declared in the PostDashboardEntity to the instance of the Post with id 64.

You can pass a closure as the value, and it will contain the current Show instance id. In most cases, you'll have to write this:

SharpShowDashboardField::make(PostDashboardEntity::class)
    ->hideFilterWithValue(PostFilter::class, fn ($instanceId) => $instanceId);

One final note: sometimes the linked filter is really just a scope, never displayed to the user. In this case, it can be tedious to write a full implementation in the Dashboard. In this situation, you can use the HiddenFiler class for the filter, passing a key:

class PostShow extends SharpShow
{
    // ...
    
    public function buildShowFields(FieldsContainer $showFields): void
    {
        $showFields->addField(
            SharpShowDashboardField::make(PostDashboardEntity::class)
                ->hideFilterWithValue('post', fn ($instanceId) => $instanceId);
        );
    }
}
use \Code16\Sharp\EntityList\Filters\HiddenFilter;

class PostDashboard extends SharpDashboard
{
    // ...

    protected function getFilters(): ?array
    {
        return [
            HiddenFilter::make('post')
        ];
    }
    
    protected function buildWidgetsData(): void
    {
        return $this->setFigureData('visit_count', 
            figure: Post::query()
                ->findOrFail($this->queryParams->filterFor('post'))
                ->get()?->visit_count
        );
    }
}

hideDashboardCommand(array|string $commands): self

Use it to hide any dashboard command in this particular Dashboard (useful when reusing a Dashboard). This will apply before looking at authorizations.

Display in layout

To display your dashboard in your show page's layout, you have to use the addDashboardSection() method in your Show Page's buildShowLayout() method.

protected function buildShowLayout(ShowLayout $showLayout): void
    {
        $showLayout
            ->addSection(function (ShowLayoutSection $section) {
                $section
                    ->addColumn(7, function (ShowLayoutColumn $column) {
                        $column
                            ->withFields(categories: 5, author: 7)
                           // ...
                    })
                    ->addColumn(5, function (ShowLayoutColumn $column) {
                        // ...
                    });
            })
            ->addDashboardSection(PostDashboardEntity::class);
    }
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle