unusualdope / banner-manager
A Laravel package for managing banners with Blade directives, Flux UI admin interface, and optional translations
Installs: 0
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/unusualdope/banner-manager
Requires
- php: ^8.2
- illuminate/support: ^10.0|^11.0|^12.0
- livewire/livewire: ^4.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
A Laravel package for managing banners with Blade directives, Flux UI admin interface, and optional multi-language support.
Features
- Flux UI Integration: Modern, responsive admin interface using Flux components.
- Group Management: Organize banners into logical groups (e.g., Homepage Hero, Sidebar).
- Flexible Content: Manage images, titles, descriptions, links, and buttons.
- Optional Translations: Toggle between single-language and multi-language banners per banner.
- Smart Carousel: Default view automatically creates an auto-playing carousel for multiple banners.
- Caching: Optimized performance with automatic cache management.
Installation
The package is installed via local path repository in this project.
Database Setup
Run the migrations:
php artisan migrate
Or publish the migrations first:
php artisan vendor:publish --tag=banner-manager-migrations php artisan migrate
Configuration
Publish the config file:
php artisan vendor:publish --tag=banner-manager-config
This will create config/banner-manager.php where you can configure:
supported_locales: List of languages (e.g.,['it', 'en'])default_locale: Fallback languageadmin_route_prefix: URL prefix for admin routes (default:admin)default_view: Template for@cmsbannerdirective
Usage
Admin Interface
Access the banner manager at: /admin/banner-manager
Managing Groups
- Create Group: Click "Create Group" on the index page.
- Edit Group: Click "Manage" on any group card. This takes you to the group edit page where you can also manage its banners.
Managing Banners
Banners are managed directly from their parent group's edit page.
- Go to a group's edit page.
- Scroll to the "Banners" section.
- Add Banner: Click the "+" button to open the banner creation page.
- Edit Banner: Click the pencil icon on any banner in the list.
- Translations: Toggle "Enable translations" to switch between single-language and multi-language mode.
- Sort Order: Banners are displayed based on the "Sort Order" field (lower numbers first).
Displaying Banners
Use the @cmsbanner Blade directive in your views:
1. Default View (Carousel)
Displays banners using the default package view. If multiple banners exist in the group, it automatically renders an auto-playing carousel with slide transitions.
@cmsbanner('homepage-hero')
2. Custom View
Pass a custom view path to render banners with your own HTML structure.
@cmsbanner('homepage-hero', ['view' => 'front.banner-manager.hero'])
3. Custom CSS Class
Add custom classes to the banner container.
@cmsbanner('sidebar-ads', ['class' => 'my-8 rounded-xl'])
Programmatic Usage
You can use the BannerService to retrieve banners directly in your controllers or PHP code:
use Unusualdope\BannerManager\Services\BannerService; $service = app(BannerService::class); // Get all banners for a group $banners = $service->getBanners('homepage-hero'); // Get banners for a specific locale $banners = $service->getBanners('homepage-hero', 'en'); // Clear cache for a group $service->clearCache('homepage-hero');
Database Structure
banner_groups
id,name,slug,description,is_active,timestamps
banners
id,banner_group_idsort_order,is_activestart_date,end_dateis_translatable(boolean)timestamps
banner_translations
id,banner_id,localetitle,descriptionimage,link_urlbutton_text,alt_textadditional_data(JSON)timestamps
Publishing Views
To customize the default views:
php artisan vendor:publish --tag=banner-manager-views
This publishes views to resources/views/front/banner-manager/.