Skip to main content
This guide covers how to add custom navigation items to the Shopper admin panel using the sidebar extension system.

Overview

Shopper uses an event-based system to build the sidebar. When the sidebar is rendered, it dispatches a SidebarBuilder 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 extends AbstractAdminSidebar:
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:
Make sure to register the listener in the register() method, not boot(), to ensure it’s registered before the sidebar is built.

Weight System

The weight 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 the routes/shopper.php file (configured in config/shopper/routes.php):
All routes in routes/shopper.php are automatically prefixed with the Shopper route prefix and have the shopper. route name prefix. So posts.index becomes shopper.blog.posts.index.