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

Add global page alert

This feature makes it possible to add a message (with an alert or not) at the top of an Entity List, a Form (including a Command Form), a Show Page, a Dashboard or an Embed.

A global page alert can be great to provide feedback to the user, to remind him of a particular state, to warn him of potential consequences of a Command...

Declaration

Create a buildPageAlert() method:

class MyShow extends SharpShow
{
    // ...
    
    protected function buildPageAlert(PageAlert $pageAlert): void
    {
        $pageAlert
            ->setLevelInfo()
            ->setMessage('This post is planned for publication');
    }
}

You can use several styles: setLevelInfo(), setLevelWarning(), setLevelDanger(), setLevelPrimary() or setLevelSecondary().

Dynamic messages

To provide a dynamic message, depending on the actual data of the Show, Entity List and so on, you can pass a closure to the setMessage() method:

class MyShow extends SharpShow
{
    // ...
    
    protected function buildPageAlert(PageAlert $pageAlert): void
    {
        $pageAlert
            ->setLevelInfo()
            ->setMessage(function (array $data) {
                return $data['is_planned']
                    ? 'This post is planned for publication, on ' . $data['published_at']
                    : null;
            });
    }
}

The $data array passed to the closure is the result of your find() (Show, Form), getListData() (Entity List), buildWidgetsData() (Dashboard) or initialData() (Command) method.

::: tip If your message is complex to build, you can defer to a blade template to encapsulate the logic, eg: return view('sharp._post-planned-info', ['data' => $data])->render(); :::

Add a button link

The setButton() method allows you to add a link to your alert:

class MyShow extends SharpShow
{
    // ...
    
    protected function buildPageAlert(PageAlert $pageAlert): void
    {
        $pageAlert
            ->setMessage('This page has been edited recently.')
            ->setButton('Go to page', route('pages.show', sharp()->context()->instanceId()));
    }
}

You can also pass a SharpLinkTo object. It's useful for filtering an Entity List, for example:

class MyEntityList extends SharpEntityList
{
    // ...
    
    protected function buildPageAlert(PageAlert $pageAlert): void
    {
        $pageAlert
            ->setMessage('There are new orders to handle.')
            ->setButton('See orders', LinkToEntityList::make(MyEntity::class)
                ->addFilter('is_new', 1)
            );
    }
}

Attach the page alert to a specific section (Show Page and Dashboard only)

The onSection() method allows you to specify the section where the alert should be displayed (instead of the default, the top of the page):

class MyShow extends SharpShow
{
    // ...
    
    protected function buildShowLayout(ShowLayout $showLayout): void
    {
        $showLayout
            ->addSection(function (ShowLayoutSection $section) {
                $section
                    ->setKey('content')
                    ->addColumn(/* ... */);
            })
            ->addSection(/* ... */);
    }
    
    protected function buildPageAlert(PageAlert $pageAlert): void
    {
        $pageAlert
            ->setMessage('This page has been edited recently.')
            ->onSection('content');
    }
}
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.
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
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope