Installation
composer require bkstg/notice-board-bundle
Add to config/app.php under ExtraBundles:
'bkstg\NoticeBoardBundle\NoticeBoardBundle' => ['all' => true],
Publish Assets
php artisan vendor:publish --provider="Bkstg\NoticeBoardBundle\NoticeBoardBundle" --tag=public
This creates a public/vendor/notice-board/ directory with JS/CSS.
First Use Case Display a simple notice in a Blade template:
@noticeBoard
@include('notice-board::default', [
'title' => 'System Update',
'message' => 'Maintenance scheduled for 2024-05-15',
'type' => 'info'
])
@endnoticeBoard
Verify the notice appears in your layout (default: top-right corner).
Notice Types
Use predefined types (info, success, warning, error) or extend via:
// config/notice-board.php
'types' => [
'custom' => ['class' => 'bg-purple-500', 'icon' => 'bell'],
],
Dynamic Notices Trigger notices from controllers:
use Bkstg\NoticeBoardBundle\NoticeBoard;
public function store(Request $request)
{
$notice = new NoticeBoard();
$notice->add('Success!', 'Data saved.', 'success');
return redirect()->back();
}
Conditional Rendering
@if(noticeBoard()->has('warning'))
@noticeBoard
@include('notice-board::default', [
'title' => 'Warning',
'message' => noticeBoard()->get('warning')->message,
])
@endnoticeBoard
@endif
Stacking Notices
$notice->add('Notice 1', 'Content 1', 'info')
->add('Notice 2', 'Content 2', 'warning');
resources/views/vendor/notice-board/.noticeBoard()->toJson() for API responses:
return response()->json(['data' => $data, 'notices' => noticeBoard()->toJson()]);
public function handle($request, Closure $next)
{
noticeBoard()->add('Global Notice', 'You have 3 unread messages.', 'info');
return $next($request);
}
Asset Loading
public/vendor/notice-board/ is symlinked or copied to public/:
php artisan notice-board:assets
config/notice-board.php for asset_path override.Notice Persistence
noticeBoard()->persist('warning', 'This is a persistent notice.');
Blade Directive Scope
@noticeBoard directives must be closed with @endnoticeBoard. Unclosed tags will break rendering.Type Validation
info. Validate in config/notice-board.php:
'strict_types' => true, // Throws exception on invalid types
noticeBoard()->clear() to reset all notices.config/notice-board.php:
'debug' => true, // Logs notices to Laravel logs
session('notice_board'). Dump with:
dd(session('notice_board'));
Custom Templates
Extend the default template by copying vendor/bkstg/notice-board-bundle/resources/views/default.blade.php to resources/views/vendor/notice-board/.
Notice Storage
Override storage engine (e.g., database) by implementing Bkstg\NoticeBoardBundle\Contracts\NoticeStorageInterface.
Event Listeners Listen for notice events:
// Event: NoticeBoard\Events\NoticeAdded
NoticeBoard::add('Custom Event', 'Triggered!', 'info');
Translation
Override translations in resources/lang/en/notice-board.php:
return [
'types' => [
'info' => 'Information',
'custom' => 'Custom Alert',
],
];
How can I help you explore Laravel packages today?