diff --git a/demo/app/Sharp/Dashboard/DemoDashboard.php b/demo/app/Sharp/Dashboard/DemoDashboard.php index fa6fb5b28..9eaaca480 100644 --- a/demo/app/Sharp/Dashboard/DemoDashboard.php +++ b/demo/app/Sharp/Dashboard/DemoDashboard.php @@ -135,6 +135,7 @@ protected function buildPageAlert(PageAlert $pageAlert): void { $pageAlert ->setLevelInfo() + ->onSection('stats-section') ->setMessage( sprintf( 'Graphs below are delimited by period %s - %s (and yes, visits figures are randomly generated)', diff --git a/demo/app/Sharp/Posts/PostShow.php b/demo/app/Sharp/Posts/PostShow.php index af8e10dbe..28eb3afd8 100644 --- a/demo/app/Sharp/Posts/PostShow.php +++ b/demo/app/Sharp/Posts/PostShow.php @@ -118,14 +118,13 @@ protected function buildPageAlert(PageAlert $pageAlert): void { $pageAlert ->setLevelInfo() - ->setMessage(function (array $data) { - return $data['publication']['is_planned'] - ? sprintf( - 'This post is planned for publication, on %s', - $data['publication']['published_at'], - ) - : null; - }); + ->setMessage(fn (array $data) => $data['publication']['is_planned'] + ? sprintf( + 'This post is planned for publication, on %s', + $data['publication']['published_at'], + ) + : null + ); } public function getInstanceCommands(): ?array diff --git a/docs/guide/page-alerts.md b/docs/guide/page-alerts.md index 0ec69c165..c23c6a3a2 100644 --- a/docs/guide/page-alerts.md +++ b/docs/guide/page-alerts.md @@ -91,3 +91,33 @@ class MyEntityList extends SharpEntityList } ``` +## 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): + +```php +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'); + } +} +``` + + diff --git a/resources/js/Pages/Dashboard/Dashboard.vue b/resources/js/Pages/Dashboard/Dashboard.vue index d2b919134..c1f934ca8 100644 --- a/resources/js/Pages/Dashboard/Dashboard.vue +++ b/resources/js/Pages/Dashboard/Dashboard.vue @@ -62,7 +62,7 @@