kenepa/banner
Filament plugin to create, schedule, and display dynamic banners in your admin panel. Manage multiple banners, customize styling, allow user dismiss, scope to specific resources/pages, control render location, add links, and create banners programmatically via a facade.
Installation
composer require kenepa/banner:^1.0
Publish the package configuration and migrations:
php artisan vendor:publish --provider="Kenepa\Banner\BannerServiceProvider" --tag="config"
php artisan vendor:publish --provider="Kenepa\Banner\BannerServiceProvider" --tag="migrations"
php artisan migrate
First Banner
Register the banner in app/Providers/AppServiceProvider.php:
use Kenepa\Banner\Facades\Banner;
public function boot()
{
Banner::add('welcome', [
'title' => 'Welcome!',
'message' => 'New updates available.',
'type' => 'success',
]);
}
Display in Blade
@banner('welcome')
Dynamic Banner Management
Banner::add() in service providers or controllers for runtime banners.Banner::add('form_success', [
'title' => 'Success!',
'message' => 'Your changes have been saved.',
'type' => 'success',
'timeout' => 5000, // Auto-dismiss in 5s
]);
Conditional Rendering
@if(Banner::exists('welcome'))
@banner('welcome')
@endif
Global vs. Local Banners
AppServiceProvider (persists across sessions).Integration with Filament (V5)
Banner::add() in Filament V5 policies, actions, or resources:
public function handle()
{
Banner::add('filament_action', [
'title' => 'Action Complete',
'message' => 'Your task was processed.',
'type' => 'info',
]);
return redirect()->back();
}
Multi-Language Support (French Added)
Banner::add('welcome', [
'title' => __('banner.welcome.title'),
'message' => __('banner.welcome.message'),
]);
app.php locale settings are configured for French ('locale' => 'fr').Custom Banner Types
Extend the default types (success, danger, warning, info) by publishing the config and adding:
'types' => [
'custom' => 'bg-blue-500 text-white',
],
Banner Storage
Override storage (e.g., cache) in config/banner.php:
'driver' => 'cache',
Programmatic Removal Clear banners in middleware or controllers:
Banner::remove('welcome');
Banner::clear(); // Remove all
API Responses Attach banners to API responses (requires custom middleware):
return response()->json($data, 200)->withBanner('welcome');
Session Dependency
AppServiceProvider persist until manually cleared. Use Banner::clear() in logout middleware if needed.Blade Cache Conflicts Clear Blade cache after adding new banners:
php artisan view:clear
Type Mismatch Errors
Ensure type in Banner::add() matches a defined type in config/banner.php. Defaults to info if invalid.
Migration Conflicts
If manually editing the banners table, reset migrations:
php artisan migrate:fresh
Filament V5 Compatibility
filament/filament:^5.0) to avoid version conflicts.Inspect Registered Banners Dump all banners in Tinker:
php artisan tinker
>>> \Kenepa\Banner\Facades\Banner::all();
Check Storage Driver
Verify config/banner.php driver setting (default: session). For cache, ensure Banner::clear() is called on cache flush.
Blade Rendering Issues
Ensure @banner('key') is placed after Banner::add() in the request lifecycle (e.g., not in a layout file before the controller runs).
French Translation Debugging If translations aren’t loading, verify:
lang/vendor/kenepa/banner/fr.json file exists (published via vendor:publish).app.php locale is set to fr or the correct locale is being overridden.Custom Blade Directives
Extend @banner with custom logic:
Blade::directive('customBanner', function ($key) {
return "<?php if (\Kenepa\Banner\Facades\Banner::exists($key)): ?>
<div class=\"custom-banner\">...</div>
<?php endif; ?>";
});
Event Listeners
Trigger actions on banner events (e.g., BannerCreated):
Banner::add('welcome', [...], function () {
// Post-add logic (e.g., analytics)
});
Filament V5 Customization Override Filament’s default notification styles to align with this package’s banners:
// In a Filament resource or page
use Kenepa\Banner\Facades\Banner;
public static function getPages(): array
{
return [
// ...
];
}
public function mount()
{
if (Banner::exists('filament_warning')) {
$this->notify('warning', Banner::get('filament_warning')->message);
}
}
How can I help you explore Laravel packages today?