Overview
Shopper uses an event-based system to build the sidebar. When the sidebar is rendered, it dispatches aSidebarBuilder event that you can listen to and add your own menu groups and items.
Creating a Sidebar Extension
1. Create an Extension Class
Create a class that extendsAbstractAdminSidebar:
The
$this->user property is available in your extension class to access the authenticated user for authorization checks.2. Register the Extension
Register your sidebar extension in a service provider:Weight System
Theweight value determines the order of items and groups. Lower values appear first:
Choose a weight value that positions your menu in the desired location.
Adding Sub-Items
Items can have nested sub-items for dropdown menus:Add
sh-items-has-child to the parent item class to enable the proper dropdown styling.Authorization
Permission-Based Authorization
Use Laravel’s authorization system to control visibility:Role-Based Authorization
Adding Badges
Show notification counts or labels on menu items:Adding Quick Actions (Append)
Add action buttons next to menu items:Complete Example
Here’s a complete example of a blog sidebar extension:Using Closures for Dynamic Sidebars
For simpler cases, you can use a closure instead of a class:Routes Configuration
Add your routes in theroutes/shopper.php file (configured in config/shopper/routes.php):